From a9add5e44a4db81f6282119085e0c83d94428872 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Tue, 15 Nov 2022 08:21:44 -0800 Subject: [PATCH] Fixed event comparison issue in Syncpointspec tests (#6786) --- .changeset/rotten-peaches-poke.md | 2 + .../database/test/helpers/syncpoint-util.ts | 68 +++++++++---------- 2 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 .changeset/rotten-peaches-poke.md diff --git a/.changeset/rotten-peaches-poke.md b/.changeset/rotten-peaches-poke.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/rotten-peaches-poke.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/database/test/helpers/syncpoint-util.ts b/packages/database/test/helpers/syncpoint-util.ts index eca60da65bf..4c28c55a9b2 100644 --- a/packages/database/test/helpers/syncpoint-util.ts +++ b/packages/database/test/helpers/syncpoint-util.ts @@ -228,7 +228,6 @@ export class SyncPointTestParser { } } }; - const EVENT_ORDERING = [ 'child_removed', 'child_added', @@ -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'); @@ -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 = @@ -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);