Skip to content

Commit d8984c1

Browse files
fix upload test
1 parent 8179aa2 commit d8984c1

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

packages/web/tests/multiple_instances.test.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
21
import { AbstractPowerSyncDatabase, SqliteBucketStorage, SyncStatus } from '@powersync/common';
32
import {
43
PowerSyncDatabase,
54
SharedWebStreamingSyncImplementation,
65
WebRemote,
76
WebStreamingSyncImplementationOptions
87
} from '@powersync/web';
9-
import { testSchema } from './utils/testDb';
10-
import { TestConnector } from './utils/MockStreamOpenFactory';
118
import { Mutex } from 'async-mutex';
129
import Logger from 'js-logger';
10+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
11+
import { TestConnector } from './utils/MockStreamOpenFactory';
12+
import { testSchema } from './utils/testDb';
1313

1414
describe('Multiple Instances', () => {
1515
const dbFilename = 'test-multiple-instances.db';
@@ -23,6 +23,8 @@ describe('Multiple Instances', () => {
2323
schema: testSchema
2424
});
2525

26+
beforeAll(() => Logger.useDefaults());
27+
2628
beforeEach(() => {
2729
db = openDatabase();
2830
});
@@ -184,34 +186,44 @@ describe('Multiple Instances', () => {
184186
});
185187

186188
// Create the first streaming client
187-
const syncOptions1: WebStreamingSyncImplementationOptions = {
189+
const stream1 = new SharedWebStreamingSyncImplementation({
188190
adapter: new SqliteBucketStorage(db.database, new Mutex()),
189191
remote: new WebRemote(connector1),
190192
uploadCrud: async () => {
191193
triggerUpload1();
192194
connector1.uploadData(db);
193195
},
194-
identifier
195-
};
196-
const stream1 = new SharedWebStreamingSyncImplementation(syncOptions1);
196+
identifier,
197+
retryDelayMs: 100,
198+
flags: {
199+
broadcastLogs: true
200+
}
201+
});
197202

198203
// Generate the second streaming sync implementation
199204
const connector2 = new TestConnector();
200-
const spy2 = vi.spyOn(connector2, 'uploadData');
205+
// The second connector will be called first to upload, we don't want it to actually upload
206+
// This will cause the sync uploads to be delayed as the CRUD queue did not change
207+
const spy2 = vi.spyOn(connector2, 'uploadData').mockImplementation(async () => {});
208+
201209
let triggerUpload2: () => void;
202210
const upload2TriggeredPromise = new Promise<void>((resolve) => {
203211
triggerUpload2 = resolve;
204212
});
205-
const syncOptions2: WebStreamingSyncImplementationOptions = {
213+
214+
const stream2 = new SharedWebStreamingSyncImplementation({
206215
adapter: new SqliteBucketStorage(db.database, new Mutex()),
207216
remote: new WebRemote(connector1),
208217
uploadCrud: async () => {
209218
triggerUpload2();
210219
connector2.uploadData(db);
211220
},
212-
identifier
213-
};
214-
const stream2 = new SharedWebStreamingSyncImplementation(syncOptions2);
221+
identifier,
222+
retryDelayMs: 100,
223+
flags: {
224+
broadcastLogs: true
225+
}
226+
});
215227

216228
// Waits for the stream to be marked as connected
217229
const stream2UpdatedPromise = new Promise<void>((resolve, reject) => {
@@ -230,6 +242,8 @@ describe('Multiple Instances', () => {
230242

231243
// The status in the second stream client should be updated
232244
await stream2UpdatedPromise;
245+
246+
console.log('stream 2 status updated');
233247
expect(stream2.isConnected).true;
234248

235249
// Create something with CRUD in it.
@@ -243,6 +257,8 @@ describe('Multiple Instances', () => {
243257
// The second connector should be called to upload
244258
await upload2TriggeredPromise;
245259

260+
console.log('2 upload was triggered');
261+
246262
// It should call the latest connected client
247263
expect(spy2).toHaveBeenCalledOnce();
248264

0 commit comments

Comments
 (0)