Skip to content

Commit

Permalink
Fixed event comparison issue in Syncpointspec tests (#6786)
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht committed Nov 15, 2022
1 parent e9fb403 commit a9add5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .changeset/rotten-peaches-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
68 changes: 32 additions & 36 deletions packages/database/test/helpers/syncpoint-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ export class SyncPointTestParser {
}
}
};

const EVENT_ORDERING = [
'child_removed',
'child_added',
Expand All @@ -244,7 +243,7 @@ export class SyncPointTestParser {
}
};

const eventSetMatch = (expected, actual) => {
const eventSetMatch = (expected: any, actual: DataEvent[]) => {
// don't worry about order for now
if (expected.length !== actual.length) {
throw new Error('Mismatched lengths');
Expand Down Expand Up @@ -292,12 +291,10 @@ export class SyncPointTestParser {
// Step 3: slice each array
const expectedSlice = currentExpected.slice(0, i);
const actualSlice = currentActual.slice(0, i);

// foreach in actual, stack up to enforce ordering, find in expected
const actualMap = {};
let actualEvent;
// foreach in actual, stack up to enforce ordering, find in expected
for (let x = 0; x < actualSlice.length; ++x) {
actualEvent = actualSlice[x];
const actualEvent = actualSlice[x];
actualEvent.eventRegistration.getEventRunner(actualEvent)();
const spec = currentSpec;
const listenId =
Expand All @@ -316,39 +313,38 @@ export class SyncPointTestParser {
// this is the first event for this listen, just initialize it
actualMap[listenId] = [actualEvent];
}
}
// Ordering has been enforced, make sure we can find this in the expected events
const found = removeIf(expectedSlice, expectedEvent => {
checkValidProperties(expectedEvent, [
'type',
'path',
'name',
'prevName',
'data'
]);
if (expectedEvent.type === actualEvent.eventType) {
if (expectedEvent.type !== 'value') {
if (expectedEvent.name !== actualEvent.snapshot.key) {
return false;
}
if (
expectedEvent.type !== 'child_removed' &&
expectedEvent.prevName !== actualEvent.prevName
) {
return false;
// Ordering has been enforced, make sure we can find this in the expected events
const found = removeIf(expectedSlice, expectedEvent => {
checkValidProperties(expectedEvent, [
'type',
'path',
'name',
'prevName',
'data'
]);
if (expectedEvent.type === actualEvent.eventType) {
if (expectedEvent.type !== 'value') {
if (expectedEvent.name !== actualEvent.snapshot.key) {
return false;
}
if (
expectedEvent.type !== 'child_removed' &&
expectedEvent.prevName !== actualEvent.prevName
) {
return false;
}
}
// make sure the snapshots match
const snapHash = actualEvent.snapshot._node.hash();
const expectedHash = nodeFromJSON(expectedEvent.data).hash();
return snapHash === expectedHash;
} else {
return false;
}
// make sure the snapshots match
const snapHash = actualEvent.snapshot._node.hash();
const expectedHash = nodeFromJSON(expectedEvent.data).hash();
return snapHash === expectedHash;
} else {
return false;
});
if (!found) {
throw new Error('Could not find matching expected event');
}
});
if (!found) {
// console.log(actualEvent);
throw new Error('Could not find matching expected event');
}
currentExpected = currentExpected.slice(i);
currentActual = currentActual.slice(i);
Expand Down

0 comments on commit a9add5e

Please sign in to comment.