Skip to content

Commit 35f3b20

Browse files
committed
Brought back event order check
1 parent 436eace commit 35f3b20

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

packages/database/test/helpers/syncpoint-util.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,20 @@ export class SyncPointTestParser {
228228
}
229229
}
230230
};
231+
const EVENT_ORDERING = [
232+
'child_removed',
233+
'child_added',
234+
'child_moved',
235+
'child_changed',
236+
'value'
237+
];
238+
const assertEventsOrdered = function (e1, e2) {
239+
const idx1 = EVENT_ORDERING.indexOf(e1);
240+
const idx2 = EVENT_ORDERING.indexOf(e2);
241+
if (idx1 > idx2) {
242+
throw new Error('Received ' + e2 + ' after ' + e1);
243+
}
244+
};
231245

232246
const eventSetMatch = (expected: any, actual: DataEvent[]) => {
233247
// don't worry about order for now
@@ -277,10 +291,28 @@ export class SyncPointTestParser {
277291
// Step 3: slice each array
278292
const expectedSlice = currentExpected.slice(0, i);
279293
const actualSlice = currentActual.slice(0, i);
280-
294+
const actualMap = {};
281295
// foreach in actual, stack up to enforce ordering, find in expected
282296
for (let x = 0; x < actualSlice.length; ++x) {
283297
const actualEvent = actualSlice[x];
298+
actualEvent.eventRegistration.getEventRunner(actualEvent)();
299+
const spec = currentSpec;
300+
const listenId =
301+
this.getTestPath(optBasePath, spec.path).toString() +
302+
'|' +
303+
spec.ref._queryIdentifier;
304+
if (listenId in actualMap) {
305+
// stack this event up, and make sure it obeys ordering constraints
306+
const eventStack = actualMap[listenId];
307+
assertEventsOrdered(
308+
eventStack[eventStack.length - 1].eventType,
309+
actualEvent.eventType
310+
);
311+
eventStack.push(actualEvent);
312+
} else {
313+
// this is the first event for this listen, just initialize it
314+
actualMap[listenId] = [actualEvent];
315+
}
284316
// Ordering has been enforced, make sure we can find this in the expected events
285317
const found = removeIf(expectedSlice, expectedEvent => {
286318
checkValidProperties(expectedEvent, [

packages/database/test/syncpoint.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ import { SyncPointTestParser } from './helpers/syncpoint-util';
1919
import syncPointSpecs from './helpers/syncPointSpec.json';
2020

2121
// TODO: We should eventually split this up into separate tests
22-
describe('Syncpoint Tests', () => {
22+
describe.only('Syncpoint Tests', () => {
2323
const util = new SyncPointTestParser();
2424
for (let i = 0; i < syncPointSpecs.length; i++) {
2525
const spec = syncPointSpecs[i];
26+
// if (
27+
// spec.name ===
28+
// 'Update (via set) the child of a co-located default listener and query'
29+
// ) {
2630
util.defineTest(spec);
31+
// }
2732
}
2833
});

0 commit comments

Comments
 (0)