@powersync/service-core 1.7.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/routes/RouterEngine.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +3 -3
- package/dist/routes/endpoints/checkpointing.d.ts +6 -6
- package/dist/routes/endpoints/socket-route.js +2 -1
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +2 -1
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +2 -1
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/ChecksumCache.d.ts +6 -6
- package/dist/storage/ChecksumCache.js +5 -6
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +9 -9
- package/dist/sync/BucketChecksumState.d.ts +8 -4
- package/dist/sync/BucketChecksumState.js +16 -8
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/SyncContext.d.ts +17 -0
- package/dist/sync/SyncContext.js +23 -0
- package/dist/sync/SyncContext.js.map +1 -0
- package/dist/sync/sync-index.d.ts +1 -0
- package/dist/sync/sync-index.js +1 -0
- package/dist/sync/sync-index.js.map +1 -1
- package/dist/sync/sync.d.ts +4 -2
- package/dist/sync/sync.js +16 -24
- package/dist/sync/sync.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +3 -0
- package/dist/system/ServiceContext.js +7 -0
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +14 -3
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/defaults.d.ts +5 -0
- package/dist/util/config/defaults.js +6 -0
- package/dist/util/config/defaults.js.map +1 -0
- package/dist/util/config/types.d.ts +7 -2
- package/dist/util/config/types.js.map +1 -1
- package/dist/util/protocol-types.d.ts +10 -10
- package/dist/util/utils.d.ts +12 -2
- package/dist/util/utils.js +5 -1
- package/dist/util/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/routes/RouterEngine.ts +1 -0
- package/src/routes/endpoints/socket-route.ts +2 -1
- package/src/routes/endpoints/sync-stream.ts +2 -1
- package/src/storage/BucketStorageBatch.ts +2 -1
- package/src/storage/ChecksumCache.ts +13 -14
- package/src/storage/SyncRulesBucketStorage.ts +10 -10
- package/src/sync/BucketChecksumState.ts +38 -12
- package/src/sync/SyncContext.ts +36 -0
- package/src/sync/sync-index.ts +1 -0
- package/src/sync/sync.ts +31 -32
- package/src/system/ServiceContext.ts +9 -0
- package/src/util/config/compound-config-collector.ts +25 -3
- package/src/util/config/defaults.ts +5 -0
- package/src/util/config/types.ts +8 -2
- package/src/util/protocol-types.ts +10 -10
- package/src/util/utils.ts +13 -2
- package/test/src/checksum_cache.test.ts +83 -84
- package/test/src/sync/BucketChecksumState.test.ts +62 -41
- package/tsconfig.tsbuildinfo +1 -1
package/src/util/utils.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as sync_rules from '@powersync/service-sync-rules';
|
|
|
2
2
|
import * as bson from 'bson';
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import * as uuid from 'uuid';
|
|
5
|
-
import { BucketChecksum,
|
|
5
|
+
import { BucketChecksum, ProtocolOpId, OplogEntry } from './protocol-types.js';
|
|
6
6
|
|
|
7
7
|
import * as storage from '../storage/storage-index.js';
|
|
8
8
|
|
|
@@ -11,6 +11,13 @@ import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
|
11
11
|
|
|
12
12
|
export type ChecksumMap = Map<string, BucketChecksum>;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* op_id as used internally, for individual operations and checkpoints.
|
|
16
|
+
*
|
|
17
|
+
* This is just a type alias, but serves to document that we're working with an op_id.
|
|
18
|
+
*/
|
|
19
|
+
export type InternalOpId = bigint;
|
|
20
|
+
|
|
14
21
|
export const ID_NAMESPACE = 'a396dd91-09fc-4017-a28d-3df722f651e9';
|
|
15
22
|
|
|
16
23
|
export function escapeIdentifier(identifier: string) {
|
|
@@ -31,7 +38,11 @@ export function hashDelete(sourceKey: string) {
|
|
|
31
38
|
return buffer.readUInt32LE(0);
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Internally we always use bigint for op_ids. Externally (in JSON) we use strings.
|
|
43
|
+
* This converts between the two.
|
|
44
|
+
*/
|
|
45
|
+
export function internalToExternalOpId(ts: InternalOpId): ProtocolOpId {
|
|
35
46
|
// Dynamic values are passed in in some cases, so we make extra sure that the
|
|
36
47
|
// number is a bigint and not number or Long.
|
|
37
48
|
if (typeof ts != 'bigint') {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ChecksumCache, FetchChecksums, FetchPartialBucketChecksum, PartialChecksum } from '@/storage/ChecksumCache.js';
|
|
2
|
-
import {
|
|
3
|
-
import { addChecksums } from '@/util/util-index.js';
|
|
2
|
+
import { addChecksums, InternalOpId } from '@/util/util-index.js';
|
|
4
3
|
import * as crypto from 'node:crypto';
|
|
5
4
|
import { describe, expect, it } from 'vitest';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Create a deterministic BucketChecksum based on the bucket name and checkpoint for testing purposes.
|
|
9
8
|
*/
|
|
10
|
-
function testHash(bucket: string, checkpoint:
|
|
9
|
+
function testHash(bucket: string, checkpoint: InternalOpId) {
|
|
11
10
|
const key = `${checkpoint}/${bucket}`;
|
|
12
11
|
const hash = crypto.createHash('sha256').update(key).digest().readInt32LE(0);
|
|
13
12
|
return hash;
|
|
@@ -77,17 +76,17 @@ describe('checksum cache', function () {
|
|
|
77
76
|
return fetchTestChecksums(batch);
|
|
78
77
|
});
|
|
79
78
|
|
|
80
|
-
expect(await cache.getChecksums(
|
|
79
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
81
80
|
|
|
82
|
-
expect(await cache.getChecksums(
|
|
81
|
+
expect(await cache.getChecksums(1234n, ['test'])).toEqual([TEST_1234]);
|
|
83
82
|
|
|
84
|
-
expect(await cache.getChecksums(
|
|
83
|
+
expect(await cache.getChecksums(123n, ['test2'])).toEqual([TEST2_123]);
|
|
85
84
|
|
|
86
85
|
expect(lookups).toEqual([
|
|
87
|
-
[{ bucket: 'test', end:
|
|
86
|
+
[{ bucket: 'test', end: 123n }],
|
|
88
87
|
// This should use the previous lookup
|
|
89
|
-
[{ bucket: 'test', start:
|
|
90
|
-
[{ bucket: 'test2', end:
|
|
88
|
+
[{ bucket: 'test', start: 123n, end: 1234n }],
|
|
89
|
+
[{ bucket: 'test2', end: 123n }]
|
|
91
90
|
]);
|
|
92
91
|
});
|
|
93
92
|
|
|
@@ -99,17 +98,17 @@ describe('checksum cache', function () {
|
|
|
99
98
|
return fetchTestChecksums(batch);
|
|
100
99
|
});
|
|
101
100
|
|
|
102
|
-
expect(await cache.getChecksums(
|
|
101
|
+
expect(await cache.getChecksums(123n, ['test2'])).toEqual([TEST2_123]);
|
|
103
102
|
|
|
104
|
-
expect(await cache.getChecksums(
|
|
103
|
+
expect(await cache.getChecksums(1234n, ['test'])).toEqual([TEST_1234]);
|
|
105
104
|
|
|
106
|
-
expect(await cache.getChecksums(
|
|
105
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
107
106
|
|
|
108
107
|
expect(lookups).toEqual([
|
|
109
108
|
// With this order, there is no option for a partial lookup
|
|
110
|
-
[{ bucket: 'test2', end:
|
|
111
|
-
[{ bucket: 'test', end:
|
|
112
|
-
[{ bucket: 'test', end:
|
|
109
|
+
[{ bucket: 'test2', end: 123n }],
|
|
110
|
+
[{ bucket: 'test', end: 1234n }],
|
|
111
|
+
[{ bucket: 'test', end: 123n }]
|
|
113
112
|
]);
|
|
114
113
|
});
|
|
115
114
|
|
|
@@ -120,9 +119,9 @@ describe('checksum cache', function () {
|
|
|
120
119
|
return fetchTestChecksums(batch);
|
|
121
120
|
});
|
|
122
121
|
|
|
123
|
-
const p1 = cache.getChecksums(
|
|
124
|
-
const p2 = cache.getChecksums(
|
|
125
|
-
const p3 = cache.getChecksums(
|
|
122
|
+
const p1 = cache.getChecksums(123n, ['test']);
|
|
123
|
+
const p2 = cache.getChecksums(1234n, ['test']);
|
|
124
|
+
const p3 = cache.getChecksums(123n, ['test2']);
|
|
126
125
|
|
|
127
126
|
expect(await p1).toEqual([TEST_123]);
|
|
128
127
|
expect(await p2).toEqual([TEST_1234]);
|
|
@@ -130,9 +129,9 @@ describe('checksum cache', function () {
|
|
|
130
129
|
|
|
131
130
|
// Concurrent requests, so we can't do a partial lookup for 123 -> 1234
|
|
132
131
|
expect(lookups).toEqual([
|
|
133
|
-
[{ bucket: 'test', end:
|
|
134
|
-
[{ bucket: 'test', end:
|
|
135
|
-
[{ bucket: 'test2', end:
|
|
132
|
+
[{ bucket: 'test', end: 123n }],
|
|
133
|
+
[{ bucket: 'test', end: 1234n }],
|
|
134
|
+
[{ bucket: 'test2', end: 123n }]
|
|
136
135
|
]);
|
|
137
136
|
});
|
|
138
137
|
|
|
@@ -143,15 +142,15 @@ describe('checksum cache', function () {
|
|
|
143
142
|
return fetchTestChecksums(batch);
|
|
144
143
|
});
|
|
145
144
|
|
|
146
|
-
const p1 = cache.getChecksums(
|
|
147
|
-
const p2 = cache.getChecksums(
|
|
145
|
+
const p1 = cache.getChecksums(123n, ['test']);
|
|
146
|
+
const p2 = cache.getChecksums(123n, ['test']);
|
|
148
147
|
|
|
149
148
|
expect(await p1).toEqual([TEST_123]);
|
|
150
149
|
|
|
151
150
|
expect(await p2).toEqual([TEST_123]);
|
|
152
151
|
|
|
153
152
|
// The lookup should be deduplicated, even though it's in progress
|
|
154
|
-
expect(lookups).toEqual([[{ bucket: 'test', end:
|
|
153
|
+
expect(lookups).toEqual([[{ bucket: 'test', end: 123n }]]);
|
|
155
154
|
});
|
|
156
155
|
|
|
157
156
|
it('should handle serial + concurrent lookups', async function () {
|
|
@@ -161,18 +160,18 @@ describe('checksum cache', function () {
|
|
|
161
160
|
return fetchTestChecksums(batch);
|
|
162
161
|
});
|
|
163
162
|
|
|
164
|
-
expect(await cache.getChecksums(
|
|
163
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
165
164
|
|
|
166
|
-
const p2 = cache.getChecksums(
|
|
167
|
-
const p3 = cache.getChecksums(
|
|
165
|
+
const p2 = cache.getChecksums(1234n, ['test']);
|
|
166
|
+
const p3 = cache.getChecksums(1234n, ['test']);
|
|
168
167
|
|
|
169
168
|
expect(await p2).toEqual([TEST_1234]);
|
|
170
169
|
expect(await p3).toEqual([TEST_1234]);
|
|
171
170
|
|
|
172
171
|
expect(lookups).toEqual([
|
|
173
|
-
[{ bucket: 'test', end:
|
|
172
|
+
[{ bucket: 'test', end: 123n }],
|
|
174
173
|
// This lookup is deduplicated
|
|
175
|
-
[{ bucket: 'test', start:
|
|
174
|
+
[{ bucket: 'test', start: 123n, end: 1234n }]
|
|
176
175
|
]);
|
|
177
176
|
});
|
|
178
177
|
|
|
@@ -183,13 +182,13 @@ describe('checksum cache', function () {
|
|
|
183
182
|
return fetchTestChecksums(batch);
|
|
184
183
|
});
|
|
185
184
|
|
|
186
|
-
expect(await cache.getChecksums(
|
|
185
|
+
expect(await cache.getChecksums(123n, ['test', 'test2'])).toEqual([TEST_123, TEST2_123]);
|
|
187
186
|
|
|
188
187
|
expect(lookups).toEqual([
|
|
189
188
|
[
|
|
190
189
|
// Both lookups in the same request
|
|
191
|
-
{ bucket: 'test', end:
|
|
192
|
-
{ bucket: 'test2', end:
|
|
190
|
+
{ bucket: 'test', end: 123n },
|
|
191
|
+
{ bucket: 'test2', end: 123n }
|
|
193
192
|
]
|
|
194
193
|
]);
|
|
195
194
|
});
|
|
@@ -201,14 +200,14 @@ describe('checksum cache', function () {
|
|
|
201
200
|
return fetchTestChecksums(batch);
|
|
202
201
|
});
|
|
203
202
|
|
|
204
|
-
expect(await cache.getChecksums(
|
|
205
|
-
expect(await cache.getChecksums(
|
|
203
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
204
|
+
expect(await cache.getChecksums(123n, ['test', 'test2'])).toEqual([TEST_123, TEST2_123]);
|
|
206
205
|
|
|
207
206
|
expect(lookups).toEqual([
|
|
208
207
|
// Request 1
|
|
209
|
-
[{ bucket: 'test', end:
|
|
208
|
+
[{ bucket: 'test', end: 123n }],
|
|
210
209
|
// Request 2
|
|
211
|
-
[{ bucket: 'test2', end:
|
|
210
|
+
[{ bucket: 'test2', end: 123n }]
|
|
212
211
|
]);
|
|
213
212
|
});
|
|
214
213
|
|
|
@@ -219,8 +218,8 @@ describe('checksum cache', function () {
|
|
|
219
218
|
return fetchTestChecksums(batch);
|
|
220
219
|
});
|
|
221
220
|
|
|
222
|
-
const a = cache.getChecksums(
|
|
223
|
-
const b = cache.getChecksums(
|
|
221
|
+
const a = cache.getChecksums(123n, ['test', 'test2']);
|
|
222
|
+
const b = cache.getChecksums(123n, ['test2', 'test3']);
|
|
224
223
|
|
|
225
224
|
expect(await a).toEqual([TEST_123, TEST2_123]);
|
|
226
225
|
expect(await b).toEqual([TEST2_123, TEST3_123]);
|
|
@@ -228,11 +227,11 @@ describe('checksum cache', function () {
|
|
|
228
227
|
expect(lookups).toEqual([
|
|
229
228
|
// Request A
|
|
230
229
|
[
|
|
231
|
-
{ bucket: 'test', end:
|
|
232
|
-
{ bucket: 'test2', end:
|
|
230
|
+
{ bucket: 'test', end: 123n },
|
|
231
|
+
{ bucket: 'test2', end: 123n }
|
|
233
232
|
],
|
|
234
233
|
// Request B (re-uses the checksum for test2 from request a)
|
|
235
|
-
[{ bucket: 'test3', end:
|
|
234
|
+
[{ bucket: 'test3', end: 123n }]
|
|
236
235
|
]);
|
|
237
236
|
});
|
|
238
237
|
|
|
@@ -243,9 +242,9 @@ describe('checksum cache', function () {
|
|
|
243
242
|
return fetchTestChecksums(batch);
|
|
244
243
|
});
|
|
245
244
|
|
|
246
|
-
expect(await cache.getChecksums(
|
|
245
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
247
246
|
|
|
248
|
-
expect(await cache.getChecksums(
|
|
247
|
+
expect(await cache.getChecksums(125n, ['test'])).toEqual([
|
|
249
248
|
{
|
|
250
249
|
bucket: 'test',
|
|
251
250
|
checksum: -1865121912,
|
|
@@ -253,7 +252,7 @@ describe('checksum cache', function () {
|
|
|
253
252
|
}
|
|
254
253
|
]);
|
|
255
254
|
|
|
256
|
-
expect(await cache.getChecksums(
|
|
255
|
+
expect(await cache.getChecksums(124n, ['test'])).toEqual([
|
|
257
256
|
{
|
|
258
257
|
bucket: 'test',
|
|
259
258
|
checksum: 1887460431,
|
|
@@ -261,9 +260,9 @@ describe('checksum cache', function () {
|
|
|
261
260
|
}
|
|
262
261
|
]);
|
|
263
262
|
expect(lookups).toEqual([
|
|
264
|
-
[{ bucket: 'test', end:
|
|
265
|
-
[{ bucket: 'test', start:
|
|
266
|
-
[{ bucket: 'test', start:
|
|
263
|
+
[{ bucket: 'test', end: 123n }],
|
|
264
|
+
[{ bucket: 'test', start: 123n, end: 125n }],
|
|
265
|
+
[{ bucket: 'test', start: 123n, end: 124n }]
|
|
267
266
|
]);
|
|
268
267
|
});
|
|
269
268
|
|
|
@@ -278,14 +277,14 @@ describe('checksum cache', function () {
|
|
|
278
277
|
return fetchTestChecksums(batch);
|
|
279
278
|
});
|
|
280
279
|
|
|
281
|
-
const a = cache.getChecksums(
|
|
282
|
-
const b = cache.getChecksums(
|
|
280
|
+
const a = cache.getChecksums(123n, ['test', 'test2']);
|
|
281
|
+
const b = cache.getChecksums(123n, ['test2', 'test3']);
|
|
283
282
|
|
|
284
283
|
await expect(a).rejects.toEqual(TEST_ERROR);
|
|
285
284
|
await expect(b).rejects.toEqual(TEST_ERROR);
|
|
286
285
|
|
|
287
|
-
const a2 = cache.getChecksums(
|
|
288
|
-
const b2 = cache.getChecksums(
|
|
286
|
+
const a2 = cache.getChecksums(123n, ['test', 'test2']);
|
|
287
|
+
const b2 = cache.getChecksums(123n, ['test2', 'test3']);
|
|
289
288
|
|
|
290
289
|
expect(await a2).toEqual([TEST_123, TEST2_123]);
|
|
291
290
|
expect(await b2).toEqual([TEST2_123, TEST3_123]);
|
|
@@ -293,16 +292,16 @@ describe('checksum cache', function () {
|
|
|
293
292
|
expect(lookups).toEqual([
|
|
294
293
|
// Request A (fails)
|
|
295
294
|
[
|
|
296
|
-
{ bucket: 'test', end:
|
|
297
|
-
{ bucket: 'test2', end:
|
|
295
|
+
{ bucket: 'test', end: 123n },
|
|
296
|
+
{ bucket: 'test2', end: 123n }
|
|
298
297
|
],
|
|
299
298
|
// Request B (re-uses the checksum for test2 from request a)
|
|
300
299
|
// Even thought the full request fails, this batch succeeds
|
|
301
|
-
[{ bucket: 'test3', end:
|
|
300
|
+
[{ bucket: 'test3', end: 123n }],
|
|
302
301
|
// Retry request A
|
|
303
302
|
[
|
|
304
|
-
{ bucket: 'test', end:
|
|
305
|
-
{ bucket: 'test2', end:
|
|
303
|
+
{ bucket: 'test', end: 123n },
|
|
304
|
+
{ bucket: 'test2', end: 123n }
|
|
306
305
|
]
|
|
307
306
|
]);
|
|
308
307
|
});
|
|
@@ -314,8 +313,8 @@ describe('checksum cache', function () {
|
|
|
314
313
|
return fetchTestChecksums(batch.filter((b) => b.bucket != 'test'));
|
|
315
314
|
});
|
|
316
315
|
|
|
317
|
-
expect(await cache.getChecksums(
|
|
318
|
-
expect(await cache.getChecksums(
|
|
316
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([{ bucket: 'test', checksum: 0, count: 0 }]);
|
|
317
|
+
expect(await cache.getChecksums(123n, ['test', 'test2'])).toEqual([
|
|
319
318
|
{ bucket: 'test', checksum: 0, count: 0 },
|
|
320
319
|
TEST2_123
|
|
321
320
|
]);
|
|
@@ -325,11 +324,11 @@ describe('checksum cache', function () {
|
|
|
325
324
|
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
326
325
|
const cache = factory(async (batch) => {
|
|
327
326
|
lookups.push(batch);
|
|
328
|
-
return fetchTestChecksums(batch.filter((b) => b.bucket != 'test' || b.end !=
|
|
327
|
+
return fetchTestChecksums(batch.filter((b) => b.bucket != 'test' || b.end != 123n));
|
|
329
328
|
});
|
|
330
329
|
|
|
331
|
-
expect(await cache.getChecksums(
|
|
332
|
-
expect(await cache.getChecksums(
|
|
330
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([{ bucket: 'test', checksum: 0, count: 0 }]);
|
|
331
|
+
expect(await cache.getChecksums(1234n, ['test'])).toEqual([
|
|
333
332
|
{
|
|
334
333
|
bucket: 'test',
|
|
335
334
|
checksum: 1597020602,
|
|
@@ -337,7 +336,7 @@ describe('checksum cache', function () {
|
|
|
337
336
|
}
|
|
338
337
|
]);
|
|
339
338
|
|
|
340
|
-
expect(lookups).toEqual([[{ bucket: 'test', end:
|
|
339
|
+
expect(lookups).toEqual([[{ bucket: 'test', end: 123n }], [{ bucket: 'test', start: 123n, end: 1234n }]]);
|
|
341
340
|
});
|
|
342
341
|
|
|
343
342
|
it('should use maxSize', async function () {
|
|
@@ -350,8 +349,8 @@ describe('checksum cache', function () {
|
|
|
350
349
|
maxSize: 2
|
|
351
350
|
});
|
|
352
351
|
|
|
353
|
-
expect(await cache.getChecksums(
|
|
354
|
-
expect(await cache.getChecksums(
|
|
352
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
353
|
+
expect(await cache.getChecksums(124n, ['test'])).toEqual([
|
|
355
354
|
{
|
|
356
355
|
bucket: 'test',
|
|
357
356
|
checksum: 1887460431,
|
|
@@ -359,36 +358,36 @@ describe('checksum cache', function () {
|
|
|
359
358
|
}
|
|
360
359
|
]);
|
|
361
360
|
|
|
362
|
-
expect(await cache.getChecksums(
|
|
361
|
+
expect(await cache.getChecksums(125n, ['test'])).toEqual([
|
|
363
362
|
{
|
|
364
363
|
bucket: 'test',
|
|
365
364
|
checksum: -1865121912,
|
|
366
365
|
count: 125
|
|
367
366
|
}
|
|
368
367
|
]);
|
|
369
|
-
expect(await cache.getChecksums(
|
|
368
|
+
expect(await cache.getChecksums(126n, ['test'])).toEqual([
|
|
370
369
|
{
|
|
371
370
|
bucket: 'test',
|
|
372
371
|
checksum: -1720007310,
|
|
373
372
|
count: 126
|
|
374
373
|
}
|
|
375
374
|
]);
|
|
376
|
-
expect(await cache.getChecksums(
|
|
375
|
+
expect(await cache.getChecksums(124n, ['test'])).toEqual([
|
|
377
376
|
{
|
|
378
377
|
bucket: 'test',
|
|
379
378
|
checksum: 1887460431,
|
|
380
379
|
count: 124
|
|
381
380
|
}
|
|
382
381
|
]);
|
|
383
|
-
expect(await cache.getChecksums(
|
|
382
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
384
383
|
|
|
385
384
|
expect(lookups).toEqual([
|
|
386
|
-
[{ bucket: 'test', end:
|
|
387
|
-
[{ bucket: 'test', start:
|
|
388
|
-
[{ bucket: 'test', start:
|
|
389
|
-
[{ bucket: 'test', start:
|
|
390
|
-
[{ bucket: 'test', end:
|
|
391
|
-
[{ bucket: 'test', end:
|
|
385
|
+
[{ bucket: 'test', end: 123n }],
|
|
386
|
+
[{ bucket: 'test', start: 123n, end: 124n }],
|
|
387
|
+
[{ bucket: 'test', start: 124n, end: 125n }],
|
|
388
|
+
[{ bucket: 'test', start: 125n, end: 126n }],
|
|
389
|
+
[{ bucket: 'test', end: 124n }],
|
|
390
|
+
[{ bucket: 'test', end: 123n }]
|
|
392
391
|
]);
|
|
393
392
|
});
|
|
394
393
|
|
|
@@ -403,10 +402,10 @@ describe('checksum cache', function () {
|
|
|
403
402
|
maxSize: 2
|
|
404
403
|
});
|
|
405
404
|
|
|
406
|
-
const p3 = cache.getChecksums(
|
|
407
|
-
const p4 = cache.getChecksums(
|
|
408
|
-
const p1 = cache.getChecksums(
|
|
409
|
-
const p2 = cache.getChecksums(
|
|
405
|
+
const p3 = cache.getChecksums(123n, ['test3']);
|
|
406
|
+
const p4 = cache.getChecksums(123n, ['test4']);
|
|
407
|
+
const p1 = cache.getChecksums(123n, ['test']);
|
|
408
|
+
const p2 = cache.getChecksums(123n, ['test2']);
|
|
410
409
|
|
|
411
410
|
expect(await p1).toEqual([TEST_123]);
|
|
412
411
|
expect(await p2).toEqual([TEST2_123]);
|
|
@@ -421,10 +420,10 @@ describe('checksum cache', function () {
|
|
|
421
420
|
|
|
422
421
|
// The lookup should be deduplicated, even though it's in progress
|
|
423
422
|
expect(lookups).toEqual([
|
|
424
|
-
[{ bucket: 'test3', end:
|
|
425
|
-
[{ bucket: 'test4', end:
|
|
426
|
-
[{ bucket: 'test', end:
|
|
427
|
-
[{ bucket: 'test2', end:
|
|
423
|
+
[{ bucket: 'test3', end: 123n }],
|
|
424
|
+
[{ bucket: 'test4', end: 123n }],
|
|
425
|
+
[{ bucket: 'test', end: 123n }],
|
|
426
|
+
[{ bucket: 'test2', end: 123n }]
|
|
428
427
|
]);
|
|
429
428
|
});
|
|
430
429
|
|
|
@@ -437,7 +436,7 @@ describe('checksum cache', function () {
|
|
|
437
436
|
return fetchTestChecksums(batch);
|
|
438
437
|
});
|
|
439
438
|
|
|
440
|
-
expect(await cache.getChecksums(
|
|
441
|
-
expect(await cache.getChecksums(
|
|
439
|
+
expect(await cache.getChecksums(123n, ['test'])).toEqual([TEST_123]);
|
|
440
|
+
expect(await cache.getChecksums(1234n, ['test'])).toEqual([TEST_1234]);
|
|
442
441
|
});
|
|
443
442
|
});
|