Skip to content

Fixed event comparison issue in Syncpointspec tests #6786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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