@powersync/service-core 0.0.0-dev-20260602073133 → 0.0.0-dev-20260803144812
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 +83 -4
- package/dist/api/RouteAPI.d.ts +42 -14
- package/dist/api/diagnostics.d.ts +12 -1
- package/dist/api/diagnostics.js +34 -22
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/commands/compact-action.js +5 -1
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +6 -2
- package/dist/modules/AbstractModule.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +26 -7
- package/dist/replication/AbstractReplicator.js +148 -68
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.d.ts +3 -3
- package/dist/replication/ReplicationModule.js.map +1 -1
- package/dist/routes/RouterEngine.d.ts +1 -0
- package/dist/routes/RouterEngine.js +6 -1
- package/dist/routes/RouterEngine.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +95 -56
- package/dist/routes/configure-fastify.js +15 -2
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/endpoints/admin.d.ts +24 -24
- package/dist/routes/endpoints/admin.js +46 -35
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.d.ts +62 -0
- package/dist/routes/endpoints/checkpointing.js +65 -7
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +3 -2
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +22 -13
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +1 -1
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/runner/teardown.js +8 -8
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +63 -17
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +22 -27
- package/dist/storage/BucketStorageFactory.js +4 -18
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/CheckpointChecksumInvalidatedError.d.ts +12 -0
- package/dist/storage/CheckpointChecksumInvalidatedError.js +17 -0
- package/dist/storage/CheckpointChecksumInvalidatedError.js.map +1 -0
- package/dist/storage/ChecksumCache.d.ts +11 -6
- package/dist/storage/ChecksumCache.js +5 -4
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/ParsedSyncConfigSet.d.ts +23 -0
- package/dist/storage/ParsedSyncConfigSet.js +2 -0
- package/dist/storage/ParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/PersistedReplicationStream.d.ts +32 -0
- package/dist/storage/PersistedReplicationStream.js +26 -0
- package/dist/storage/PersistedReplicationStream.js.map +1 -0
- package/dist/storage/PersistedSyncConfigContent.d.ts +63 -0
- package/dist/storage/PersistedSyncConfigContent.js +125 -0
- package/dist/storage/PersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/PersistedSyncConfigStatus.d.ts +13 -0
- package/dist/storage/PersistedSyncConfigStatus.js +2 -0
- package/dist/storage/PersistedSyncConfigStatus.js.map +1 -0
- package/dist/storage/SourceEntity.d.ts +6 -0
- package/dist/storage/SourceTable.d.ts +21 -3
- package/dist/storage/SourceTable.js +26 -3
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +119 -21
- package/dist/storage/SyncRulesBucketStorage.js +3 -0
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/WriteCheckpointAPI.d.ts +60 -3
- package/dist/storage/WriteCheckpointAPI.js +33 -0
- package/dist/storage/WriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +117 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +277 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.d.ts +6 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js +31 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.d.ts +17 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js +62 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js.map +1 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.d.ts +15 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js +20 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js.map +1 -0
- package/dist/storage/storage-index.d.ts +9 -1
- package/dist/storage/storage-index.js +9 -1
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/BucketChecksumState.d.ts +12 -2
- package/dist/sync/BucketChecksumState.js +69 -21
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/RequestTracker.d.ts +7 -0
- package/dist/sync/RequestTracker.js +12 -0
- package/dist/sync/RequestTracker.js.map +1 -1
- package/dist/sync/sync.js +154 -41
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.d.ts +5 -0
- package/dist/sync/util.js +9 -0
- package/dist/sync/util.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +2 -0
- package/dist/system/ServiceContext.js +2 -0
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/tracing/PerformanceTracer.d.ts +23 -1
- package/dist/tracing/PerformanceTracer.js +11 -0
- package/dist/tracing/PerformanceTracer.js.map +1 -1
- package/dist/util/checkpointing.d.ts +4 -8
- package/dist/util/checkpointing.js +1 -16
- package/dist/util/checkpointing.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +18 -2
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/defaults.d.ts +2 -0
- package/dist/util/config/defaults.js +2 -0
- package/dist/util/config/defaults.js.map +1 -1
- package/dist/util/config/types.d.ts +3 -1
- package/dist/util/lsn.d.ts +4 -0
- package/dist/util/lsn.js +10 -0
- package/dist/util/lsn.js.map +1 -1
- package/dist/util/util-index.d.ts +1 -0
- package/dist/util/util-index.js +1 -0
- package/dist/util/util-index.js.map +1 -1
- package/dist/util/utils.d.ts +1 -1
- package/dist/util/utils.js +1 -1
- package/dist/util/write-checkpoint-batcher.d.ts +19 -0
- package/dist/util/write-checkpoint-batcher.js +100 -0
- package/dist/util/write-checkpoint-batcher.js.map +1 -0
- package/package.json +6 -7
- package/src/api/RouteAPI.ts +43 -14
- package/src/api/diagnostics.ts +43 -26
- package/src/entry/commands/compact-action.ts +7 -1
- package/src/modules/AbstractModule.ts +6 -2
- package/src/replication/AbstractReplicator.ts +181 -72
- package/src/replication/ReplicationModule.ts +2 -3
- package/src/routes/RouterEngine.ts +7 -1
- package/src/routes/configure-fastify.ts +25 -2
- package/src/routes/endpoints/admin.ts +72 -50
- package/src/routes/endpoints/checkpointing.ts +79 -8
- package/src/routes/endpoints/socket-route.ts +3 -2
- package/src/routes/endpoints/sync-rules.ts +23 -13
- package/src/routes/endpoints/sync-stream.ts +1 -1
- package/src/runner/teardown.ts +8 -8
- package/src/storage/BucketStorageBatch.ts +64 -18
- package/src/storage/BucketStorageFactory.ts +30 -39
- package/src/storage/CheckpointChecksumInvalidatedError.ts +17 -0
- package/src/storage/ChecksumCache.ts +27 -14
- package/src/storage/ParsedSyncConfigSet.ts +25 -0
- package/src/storage/PersistedReplicationStream.ts +55 -0
- package/src/storage/PersistedSyncConfigContent.ts +192 -0
- package/src/storage/PersistedSyncConfigStatus.ts +14 -0
- package/src/storage/SourceEntity.ts +6 -0
- package/src/storage/SourceTable.ts +34 -3
- package/src/storage/SyncRulesBucketStorage.ts +138 -22
- package/src/storage/WriteCheckpointAPI.ts +108 -3
- package/src/storage/implementation/BucketDefinitionMapping.ts +436 -0
- package/src/storage/implementation/IncrementalReprocessingCompatibility.ts +41 -0
- package/src/storage/implementation/IncrementalReprocessingSyncConfigLog.ts +109 -0
- package/src/storage/implementation/ReplicationStreamStorageIds.ts +21 -0
- package/src/storage/storage-index.ts +10 -1
- package/src/sync/BucketChecksumState.ts +103 -21
- package/src/sync/RequestTracker.ts +20 -0
- package/src/sync/sync.ts +183 -48
- package/src/sync/util.ts +12 -0
- package/src/system/ServiceContext.ts +7 -0
- package/src/tracing/PerformanceTracer.ts +41 -1
- package/src/util/checkpointing.ts +4 -22
- package/src/util/config/compound-config-collector.ts +25 -1
- package/src/util/config/defaults.ts +2 -0
- package/src/util/config/types.ts +3 -1
- package/src/util/lsn.ts +9 -0
- package/src/util/util-index.ts +1 -0
- package/src/util/utils.ts +1 -1
- package/src/util/write-checkpoint-batcher.ts +142 -0
- package/test/src/AbstractReplicator.test.ts +115 -0
- package/test/src/checksum_cache.test.ts +22 -0
- package/test/src/config.test.ts +102 -0
- package/test/src/diagnostics.test.ts +62 -34
- package/test/src/module-loader.test.ts +33 -1
- package/test/src/routes/admin.test.ts +182 -18
- package/test/src/routes/checkpointing.test.ts +54 -0
- package/test/src/routes/mocks.ts +6 -2
- package/test/src/storage/SourceTable.test.ts +89 -0
- package/test/src/sync/BucketChecksumState.test.ts +98 -12
- package/test/src/sync/util.test.ts +13 -1
- package/test/src/util/checkpointing.test.ts +249 -0
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +0 -59
- package/dist/storage/PersistedSyncRulesContent.js +0 -100
- package/dist/storage/PersistedSyncRulesContent.js.map +0 -1
- package/src/storage/PersistedSyncRulesContent.ts +0 -174
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { createWriteCheckpoint, storage, WriteCheckpointBatcher } from '@/index.js';
|
|
2
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
function deferred<T = void>() {
|
|
5
|
+
return Promise.withResolvers<T>();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async function waitForAsyncWork() {
|
|
9
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
10
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createStorage(options?: { shouldAdvance?: (checkpoint: { user_id: string }) => boolean }) {
|
|
14
|
+
let nextCheckpoint = 1n;
|
|
15
|
+
const bucketStorage = {
|
|
16
|
+
createManagedWriteCheckpoints: vi.fn(async (checkpoints: { user_id: string }[]) => {
|
|
17
|
+
return {
|
|
18
|
+
writeCheckpoints: new Map(checkpoints.map((checkpoint) => [checkpoint.user_id, nextCheckpoint++])),
|
|
19
|
+
shouldAdvance: checkpoints.some((checkpoint) => options?.shouldAdvance?.(checkpoint) ?? true)
|
|
20
|
+
};
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const storage = {
|
|
25
|
+
getActiveSyncConfig: vi.fn(async () => ({ storage: bucketStorage }))
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return { bucketStorage, storage };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Mock RouteAPI.createReplicationHead. The callback persists the write-checkpoint
|
|
33
|
+
* mapping and returns { response, shouldAdvance }; the source marker (tracked by
|
|
34
|
+
* `advanceMarker`) is only forced when shouldAdvance is true. An optional gate per
|
|
35
|
+
* batch keeps the call in flight so concurrency can be exercised.
|
|
36
|
+
*/
|
|
37
|
+
function createApi(options?: { gates?: PromiseWithResolvers<void>[] }) {
|
|
38
|
+
const advanceMarker = vi.fn(async (_head: string) => undefined);
|
|
39
|
+
const createReplicationHead = vi.fn(
|
|
40
|
+
async (callback: (head: string) => Promise<{ response: unknown; shouldAdvance: boolean }>) => {
|
|
41
|
+
const batch = createReplicationHead.mock.calls.length;
|
|
42
|
+
const head = `head-${batch}`;
|
|
43
|
+
const { response, shouldAdvance } = await callback(head);
|
|
44
|
+
if (shouldAdvance) {
|
|
45
|
+
await advanceMarker(head);
|
|
46
|
+
}
|
|
47
|
+
if (options?.gates) {
|
|
48
|
+
await options.gates[batch - 1].promise;
|
|
49
|
+
}
|
|
50
|
+
return response;
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
return { createReplicationHead, advanceMarker };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createBatcher(api: any, storage: any) {
|
|
57
|
+
return new WriteCheckpointBatcher(
|
|
58
|
+
() => api,
|
|
59
|
+
() => storage
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('write checkpoint batching', () => {
|
|
64
|
+
test('deduplicates managed checkpoints by greatest supplied request id per user', () => {
|
|
65
|
+
expect(
|
|
66
|
+
storage.uniqueManagedWriteCheckpoints([
|
|
67
|
+
{ user_id: 'user-a', heads: { '1': 'generated' } },
|
|
68
|
+
{ user_id: 'user-a', heads: { '1': 'stale' }, checkpoint_request_id: 41n },
|
|
69
|
+
{ user_id: 'user-a', heads: { '1': 'winner' }, checkpoint_request_id: 43n },
|
|
70
|
+
{ user_id: 'user-a', heads: { '1': 'lower' }, checkpoint_request_id: 42n },
|
|
71
|
+
{ user_id: 'user-b', heads: { '1': 'generated-b' } }
|
|
72
|
+
])
|
|
73
|
+
).toEqual([
|
|
74
|
+
{ user_id: 'user-a', heads: { '1': 'winner' }, checkpoint_request_id: 43n },
|
|
75
|
+
{ user_id: 'user-b', heads: { '1': 'generated-b' } }
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('coalesces same-turn requests and dispatches queued requests as capacity becomes available', async () => {
|
|
80
|
+
const gates = [deferred(), deferred()];
|
|
81
|
+
const { bucketStorage, storage } = createStorage();
|
|
82
|
+
const api = createApi({ gates });
|
|
83
|
+
const batcher = createBatcher(api, storage);
|
|
84
|
+
|
|
85
|
+
const firstBatch = [
|
|
86
|
+
createWriteCheckpoint({
|
|
87
|
+
userId: 'user-a',
|
|
88
|
+
clientId: 'client-1',
|
|
89
|
+
batcher
|
|
90
|
+
}),
|
|
91
|
+
createWriteCheckpoint({
|
|
92
|
+
userId: 'user-b',
|
|
93
|
+
clientId: undefined,
|
|
94
|
+
batcher
|
|
95
|
+
})
|
|
96
|
+
];
|
|
97
|
+
await waitForAsyncWork();
|
|
98
|
+
|
|
99
|
+
expect(api.createReplicationHead).toHaveBeenCalledTimes(1);
|
|
100
|
+
expect(bucketStorage.createManagedWriteCheckpoints).toHaveBeenNthCalledWith(1, [
|
|
101
|
+
{ user_id: 'user-a/client-1', heads: { '1': 'head-1' } },
|
|
102
|
+
{ user_id: 'user-b', heads: { '1': 'head-1' } }
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
const secondBatch = [
|
|
106
|
+
createWriteCheckpoint({ userId: 'user-c', clientId: 'client-3', batcher }),
|
|
107
|
+
createWriteCheckpoint({ userId: 'user-d', clientId: undefined, batcher }),
|
|
108
|
+
createWriteCheckpoint({ userId: 'user-e', clientId: undefined, batcher })
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
await waitForAsyncWork();
|
|
112
|
+
|
|
113
|
+
expect(api.createReplicationHead).toHaveBeenCalledTimes(2);
|
|
114
|
+
expect(bucketStorage.createManagedWriteCheckpoints).toHaveBeenNthCalledWith(2, [
|
|
115
|
+
{ user_id: 'user-c/client-3', heads: { '1': 'head-2' } },
|
|
116
|
+
{ user_id: 'user-d', heads: { '1': 'head-2' } },
|
|
117
|
+
{ user_id: 'user-e', heads: { '1': 'head-2' } }
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
gates[0].resolve();
|
|
121
|
+
gates[1].resolve();
|
|
122
|
+
await expect(Promise.all([...firstBatch, ...secondBatch])).resolves.toEqual([
|
|
123
|
+
{ writeCheckpoint: '1', replicationHead: 'head-1' },
|
|
124
|
+
{ writeCheckpoint: '2', replicationHead: 'head-1' },
|
|
125
|
+
{ writeCheckpoint: '3', replicationHead: 'head-2' },
|
|
126
|
+
{ writeCheckpoint: '4', replicationHead: 'head-2' },
|
|
127
|
+
{ writeCheckpoint: '5', replicationHead: 'head-2' }
|
|
128
|
+
]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('passes supplied checkpoint request ids into the storage batch', async () => {
|
|
132
|
+
const { bucketStorage, storage } = createStorage();
|
|
133
|
+
const api = createApi();
|
|
134
|
+
const batcher = createBatcher(api, storage);
|
|
135
|
+
|
|
136
|
+
await expect(
|
|
137
|
+
createWriteCheckpoint({
|
|
138
|
+
userId: 'user-a',
|
|
139
|
+
clientId: 'client-1',
|
|
140
|
+
checkpointRequestId: 42n,
|
|
141
|
+
batcher
|
|
142
|
+
})
|
|
143
|
+
).resolves.toEqual({ writeCheckpoint: '1', replicationHead: 'head-1' });
|
|
144
|
+
|
|
145
|
+
expect(bucketStorage.createManagedWriteCheckpoints).toHaveBeenCalledWith([
|
|
146
|
+
{
|
|
147
|
+
user_id: 'user-a/client-1',
|
|
148
|
+
heads: { '1': 'head-1' },
|
|
149
|
+
checkpoint_request_id: 42n
|
|
150
|
+
}
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('does not advance the source marker when storage reports no checkpoint updates', async () => {
|
|
155
|
+
const { storage } = createStorage({ shouldAdvance: () => false });
|
|
156
|
+
const api = createApi();
|
|
157
|
+
const batcher = createBatcher(api, storage);
|
|
158
|
+
|
|
159
|
+
await expect(createWriteCheckpoint({ userId: 'user-a', clientId: undefined, batcher })).resolves.toEqual({
|
|
160
|
+
writeCheckpoint: '1',
|
|
161
|
+
replicationHead: 'head-1'
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(api.createReplicationHead).toHaveBeenCalledTimes(1);
|
|
165
|
+
expect(api.advanceMarker).not.toHaveBeenCalled();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('advances the source marker when storage reports a checkpoint update', async () => {
|
|
169
|
+
const { storage } = createStorage();
|
|
170
|
+
const api = createApi();
|
|
171
|
+
const batcher = createBatcher(api, storage);
|
|
172
|
+
|
|
173
|
+
await createWriteCheckpoint({ userId: 'user-a', clientId: undefined, batcher });
|
|
174
|
+
|
|
175
|
+
expect(api.advanceMarker).toHaveBeenCalledTimes(1);
|
|
176
|
+
expect(api.advanceMarker).toHaveBeenCalledWith('head-1');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('allows three executing batches and queues later requests until one completes', async () => {
|
|
180
|
+
const gates = [deferred(), deferred(), deferred(), deferred()];
|
|
181
|
+
const { storage } = createStorage();
|
|
182
|
+
const api = createApi({ gates });
|
|
183
|
+
const batcher = createBatcher(api, storage);
|
|
184
|
+
|
|
185
|
+
const first = createWriteCheckpoint({
|
|
186
|
+
userId: 'user-a',
|
|
187
|
+
clientId: undefined,
|
|
188
|
+
batcher
|
|
189
|
+
});
|
|
190
|
+
await waitForAsyncWork();
|
|
191
|
+
|
|
192
|
+
const second = createWriteCheckpoint({
|
|
193
|
+
userId: 'user-b',
|
|
194
|
+
clientId: undefined,
|
|
195
|
+
batcher
|
|
196
|
+
});
|
|
197
|
+
await waitForAsyncWork();
|
|
198
|
+
|
|
199
|
+
const third = createWriteCheckpoint({
|
|
200
|
+
userId: 'user-c',
|
|
201
|
+
clientId: undefined,
|
|
202
|
+
batcher
|
|
203
|
+
});
|
|
204
|
+
await waitForAsyncWork();
|
|
205
|
+
|
|
206
|
+
expect(api.createReplicationHead).toHaveBeenCalledTimes(3);
|
|
207
|
+
|
|
208
|
+
const fourth = createWriteCheckpoint({
|
|
209
|
+
userId: 'user-d',
|
|
210
|
+
clientId: undefined,
|
|
211
|
+
batcher
|
|
212
|
+
});
|
|
213
|
+
await waitForAsyncWork();
|
|
214
|
+
|
|
215
|
+
expect(api.createReplicationHead).toHaveBeenCalledTimes(3);
|
|
216
|
+
|
|
217
|
+
gates[0].resolve();
|
|
218
|
+
await first;
|
|
219
|
+
await waitForAsyncWork();
|
|
220
|
+
|
|
221
|
+
expect(api.createReplicationHead).toHaveBeenCalledTimes(4);
|
|
222
|
+
|
|
223
|
+
gates[1].resolve();
|
|
224
|
+
gates[2].resolve();
|
|
225
|
+
gates[3].resolve();
|
|
226
|
+
|
|
227
|
+
await expect(Promise.all([second, third, fourth])).resolves.toEqual([
|
|
228
|
+
{ writeCheckpoint: '2', replicationHead: 'head-2' },
|
|
229
|
+
{ writeCheckpoint: '3', replicationHead: 'head-3' },
|
|
230
|
+
{ writeCheckpoint: '4', replicationHead: 'head-4' }
|
|
231
|
+
]);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('passes batch errors through without retrying', async () => {
|
|
235
|
+
const error = new Error('source unavailable');
|
|
236
|
+
const { storage } = createStorage();
|
|
237
|
+
const api = {
|
|
238
|
+
createReplicationHead: vi.fn(async () => {
|
|
239
|
+
throw error;
|
|
240
|
+
}),
|
|
241
|
+
advanceMarker: vi.fn(async () => undefined)
|
|
242
|
+
};
|
|
243
|
+
const batcher = createBatcher(api, storage);
|
|
244
|
+
|
|
245
|
+
await expect(createWriteCheckpoint({ userId: 'user-a', clientId: undefined, batcher })).rejects.toBe(error);
|
|
246
|
+
expect(api.createReplicationHead).toHaveBeenCalledTimes(1);
|
|
247
|
+
expect(api.advanceMarker).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
249
|
+
});
|
package/tsconfig.json
CHANGED