Skip to content

Commit 4a12be8

Browse files
increase timeouts
1 parent 9cadf24 commit 4a12be8

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

packages/web/tests/multiple_instances.test.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { beforeAll, describe, expect, it, onTestFinished, vi } from 'vitest';
55
import { LockedAsyncDatabaseAdapter } from '../src/db/adapters/LockedAsyncDatabaseAdapter';
66
import { WebDBAdapter } from '../src/db/adapters/WebDBAdapter';
77
import { WorkerWrappedAsyncDatabaseConnection } from '../src/db/adapters/WorkerWrappedAsyncDatabaseConnection';
8-
import { getMockSyncServiceFromWorker } from './utils/MockSyncServiceClient';
98
import { createTestConnector, sharedMockSyncServiceTest } from './utils/mockSyncServiceTest';
109
import { generateTestDb, testSchema } from './utils/testDb';
1110

@@ -41,7 +40,7 @@ describe('Multiple Instances', { sequential: true }, () => {
4140
sharedMockSyncServiceTest(
4241
'should broadcast logs from shared sync worker',
4342
{ timeout: 10_000 },
44-
async ({ context: { openDatabase } }) => {
43+
async ({ context: { openDatabase, mockService } }) => {
4544
const logger = createLogger('test-logger');
4645
const spiedErrorLogger = vi.spyOn(logger, 'error');
4746
const spiedDebugLogger = vi.spyOn(logger, 'debug');
@@ -61,18 +60,17 @@ describe('Multiple Instances', { sequential: true }, () => {
6160
uploadData: async (db) => {}
6261
});
6362

64-
await vi.waitFor(async () => {
65-
const syncService = await getMockSyncServiceFromWorker(powersync.database.name);
66-
if (!syncService) {
67-
throw new Error('Sync service not found');
68-
}
69-
const requests = await syncService.getPendingRequests();
70-
expect(requests.length).toBeGreaterThan(0);
71-
const pendingRequestId = requests[0].id;
72-
// Generate an error
73-
await syncService.createResponse(pendingRequestId, 401, { 'Content-Type': 'application/json' });
74-
await syncService.completeResponse(pendingRequestId);
75-
});
63+
await vi.waitFor(
64+
async () => {
65+
const requests = await mockService.getPendingRequests();
66+
expect(requests.length).toBeGreaterThan(0);
67+
const pendingRequestId = requests[0].id;
68+
// Generate an error
69+
await mockService.createResponse(pendingRequestId, 401, { 'Content-Type': 'application/json' });
70+
await mockService.completeResponse(pendingRequestId);
71+
},
72+
{ timeout: 3_000 }
73+
);
7674

7775
// Should log that a connection attempt has been made
7876
const message = 'Streaming sync iteration started';
@@ -224,22 +222,26 @@ describe('Multiple Instances', { sequential: true }, () => {
224222
await watchedPromise;
225223
});
226224

227-
sharedMockSyncServiceTest('should share sync updates', async ({ context: { database, connect, openDatabase } }) => {
228-
const secondDatabase = openDatabase();
225+
sharedMockSyncServiceTest(
226+
'should share sync updates',
227+
{ timeout: 10_000 },
228+
async ({ context: { database, connect, openDatabase } }) => {
229+
const secondDatabase = openDatabase();
229230

230-
expect(database.currentStatus.connected).false;
231-
expect(secondDatabase.currentStatus.connected).false;
232-
// connect the second database in order for it to have access to the sync service.
233-
secondDatabase.connect(createTestConnector());
234-
// Timing of this can be tricky due to the need for responding to a pending request.
235-
await vi.waitFor(() => expect(secondDatabase.currentStatus.connecting).true, { timeout: 2000 });
236-
// connect the first database - this will actually connect to the sync service.
237-
await connect();
231+
expect(database.currentStatus.connected).false;
232+
expect(secondDatabase.currentStatus.connected).false;
233+
// connect the second database in order for it to have access to the sync service.
234+
secondDatabase.connect(createTestConnector());
235+
// Timing of this can be tricky due to the need for responding to a pending request.
236+
await vi.waitFor(() => expect(secondDatabase.currentStatus.connecting).true, { timeout: 5_000 });
237+
// connect the first database - this will actually connect to the sync service.
238+
await connect();
238239

239-
expect(database.currentStatus.connected).true;
240+
expect(database.currentStatus.connected).true;
240241

241-
await vi.waitFor(() => expect(secondDatabase.currentStatus.connected).true, { timeout: 3000 });
242-
});
242+
await vi.waitFor(() => expect(secondDatabase.currentStatus.connected).true, { timeout: 5_000 });
243+
}
244+
);
243245

244246
sharedMockSyncServiceTest(
245247
'should trigger uploads from last connected clients',

0 commit comments

Comments
 (0)