Skip to content

Commit feca863

Browse files
fix broken test
1 parent 8721538 commit feca863

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { CrudEntry } from '../bucket/CrudEntry.js';
1717
import { SyncDataBucket } from '../bucket/SyncDataBucket.js';
1818
import { AbstractRemote, FetchStrategy, SyncStreamOptions } from './AbstractRemote.js';
19-
import { coreStatusToJs, EstablishSyncStream, Instruction, SyncPriorityStatus } from './core-instruction.js';
19+
import { EstablishSyncStream, Instruction, coreStatusToJs } from './core-instruction.js';
2020
import {
2121
BucketRequest,
2222
CrudUploadNotification,

packages/web/src/db/sync/SharedWebStreamingSyncImplementation.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,25 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
146146
).port;
147147
}
148148

149+
/**
150+
* Pass along any sync status updates to this listener
151+
*/
152+
this.clientProvider = new SharedSyncClientProvider(
153+
this.webOptions,
154+
(status) => {
155+
this.updateSyncStatus(status);
156+
},
157+
options.db
158+
);
159+
149160
this.syncManager = Comlink.wrap<WorkerClient>(this.messagePort);
161+
/**
162+
* The sync worker will call this client provider when it needs
163+
* to fetch credentials or upload data.
164+
* This performs bi-directional method calling.
165+
*/
166+
Comlink.expose(this.clientProvider, this.messagePort);
167+
150168
this.syncManager.setLogLevel(this.logger.getLevel());
151169

152170
this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
@@ -159,17 +177,6 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
159177
*/
160178

161179
this.isInitialized = this._init();
162-
163-
/**
164-
* Pass along any sync status updates to this listener
165-
*/
166-
this.clientProvider = new SharedSyncClientProvider(
167-
this.webOptions,
168-
(status) => {
169-
this.iterateListeners((l) => this.updateSyncStatus(status));
170-
},
171-
options.db
172-
);
173180
}
174181

175182
protected async _init() {
@@ -190,30 +197,24 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
190197
// to free resources associated with this tab.
191198
// We take hold of this lock as soon-as-possible in order to cater for potentially closed tabs.
192199
getNavigatorLocks().request(`tab-close-signal-${crypto.randomUUID()}`, async (lock) => {
193-
if (!this.abortOnClose.signal.aborted) {
194-
// Awaiting here ensures the worker is waiting for the lock
195-
await this.syncManager.addLockBasedCloseSignal(lock!.name);
200+
if (this.abortOnClose.signal.aborted) {
201+
return;
202+
}
203+
// Awaiting here ensures the worker is waiting for the lock
204+
await this.syncManager.addLockBasedCloseSignal(lock!.name);
196205

197-
// The lock has been registered, we can continue with the initialization
198-
resolve();
206+
// The lock has been registered, we can continue with the initialization
207+
resolve();
199208

200-
await new Promise<void>((r) => {
201-
this.abortOnClose.signal.onabort = () => r();
202-
});
203-
}
209+
await new Promise<void>((r) => {
210+
this.abortOnClose.signal.onabort = () => r();
211+
});
204212
});
205213
});
206214

207215
const { crudUploadThrottleMs, identifier, retryDelayMs } = this.options;
208216
const flags = { ...this.webOptions.flags, workers: undefined };
209217

210-
/**
211-
* The sync worker will call this client provider when it needs
212-
* to fetch credentials or upload data.
213-
* This performs bi-directional method calling.
214-
*/
215-
Comlink.expose(this.clientProvider, this.messagePort);
216-
217218
await this.syncManager.setParams(
218219
{
219220
dbParams: this.dbAdapter.getConfiguration(),

packages/web/tests/multiple_instances.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ describe('Multiple Instances', { sequential: true }, () => {
380380
// Close the second client, leaving only the first one
381381
await stream2.dispose();
382382

383+
// The dispose above will disconnect, but we need to wait for the sync stream to be created before we can update the status
384+
await vi.waitFor(() => expect(stream1.syncStatus.connecting).true);
383385
// Hack, set the status to connected in order to trigger the upload
384386
await (stream1 as any)['_testUpdateStatus'](new SyncStatus({ connected: true }));
385387
stream1.triggerCrudUpload();

0 commit comments

Comments
 (0)