-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial test for BucketChecksumState.
- Loading branch information
Showing
5 changed files
with
153 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/service-core/test/src/sync/checksum_state.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { BucketChecksum, BucketChecksumState, BucketChecksumStateStorage } from '@/index.js'; | ||
import { RequestParameters, SqlSyncRules } from '@powersync/service-sync-rules'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
describe('BucketChecksumState', () => { | ||
test('global bucket', async () => { | ||
const storage: BucketChecksumStateStorage = { | ||
async getChecksums(checkpoint, buckets) { | ||
return new Map<string, BucketChecksum>( | ||
buckets.map((b, i) => { | ||
return [ | ||
b, | ||
{ | ||
bucket: b, | ||
checksum: Number(checkpoint), | ||
count: i | ||
} | ||
]; | ||
}) | ||
); | ||
}, | ||
getParameterSets(checkpoint, lookups) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
}; | ||
|
||
const syncRules = SqlSyncRules.fromYaml( | ||
` | ||
bucket_definitions: | ||
global: | ||
data: [] | ||
`, | ||
{ defaultSchema: 'public' } | ||
); | ||
const state = new BucketChecksumState({ | ||
initialBucketState: new Map(), | ||
syncParams: new RequestParameters({ sub: '' }, {}), | ||
syncRules: syncRules, | ||
bucketStorage: storage | ||
}); | ||
|
||
const line = (await state.buildNextCheckpointLine({ base: { checkpoint: '1', lsn: '1' }, writeCheckpoint: null }))!; | ||
expect(line.checkpointLine).toEqual({ | ||
checkpoint: { | ||
buckets: [{ bucket: 'global[]', checksum: 1, count: 0, priority: 3 }], | ||
last_op_id: '1', | ||
write_checkpoint: undefined | ||
} | ||
}); | ||
expect(line.bucketsToFetch).toEqual([ | ||
{ | ||
bucket: 'global[]', | ||
priority: 3 | ||
} | ||
]); | ||
|
||
state.checkpointFilter({ | ||
invalidate: true | ||
}); | ||
|
||
const line2 = (await state.buildNextCheckpointLine({ | ||
base: { checkpoint: '2', lsn: '2' }, | ||
writeCheckpoint: null | ||
}))!; | ||
expect(line2.checkpointLine).toEqual({ | ||
checkpoint_diff: { | ||
removed_buckets: [], | ||
updated_buckets: [{ bucket: 'global[]', checksum: 2, count: 0, priority: 3 }], | ||
last_op_id: '2', | ||
write_checkpoint: undefined | ||
} | ||
}); | ||
}); | ||
}); |