Allow overriding WebSocket implementation and add flaky version for testing
This commit is contained in:
parent
74a8060246
commit
3ec6bd4d5b
8 changed files with 162 additions and 73 deletions
|
|
@ -21,13 +21,13 @@ export class SyncService {
|
|||
private static readonly NETWORK_RETRY_INTERVAL_MS = 1000;
|
||||
private client: Client<paths>;
|
||||
private pingClient: Client<paths>;
|
||||
private _fetchImplementation: typeof globalThis.fetch = globalThis.fetch;
|
||||
|
||||
public constructor(
|
||||
private readonly deviceId: string,
|
||||
private readonly connectionStatus: ConnectionStatus,
|
||||
private readonly settings: Settings,
|
||||
private readonly logger: Logger
|
||||
private readonly logger: Logger,
|
||||
private readonly fetchImplementation: typeof globalThis.fetch = globalThis.fetch
|
||||
) {
|
||||
[this.client, this.pingClient] = this.createClient(
|
||||
this.settings.getSettings().remoteUri
|
||||
|
|
@ -44,13 +44,6 @@ export class SyncService {
|
|||
});
|
||||
}
|
||||
|
||||
public set fetchImplementation(fetch: typeof globalThis.fetch) {
|
||||
this._fetchImplementation = fetch;
|
||||
[this.client, this.pingClient] = this.createClient(
|
||||
this.settings.getSettings().remoteUri
|
||||
);
|
||||
}
|
||||
|
||||
private static formatError(
|
||||
error: components["schemas"]["SerializedError"]
|
||||
): string {
|
||||
|
|
@ -329,7 +322,7 @@ export class SyncService {
|
|||
baseUrl: remoteUri,
|
||||
fetch: this.connectionStatus.getFetchImplementation(
|
||||
this.logger,
|
||||
this._fetchImplementation
|
||||
this.fetchImplementation
|
||||
),
|
||||
headers: {
|
||||
authorization: `Bearer ${this.settings.getSettings().token}`
|
||||
|
|
@ -337,7 +330,7 @@ export class SyncService {
|
|||
}),
|
||||
createClient<paths>({
|
||||
baseUrl: remoteUri,
|
||||
fetch: this._fetchImplementation,
|
||||
fetch: this.fetchImplementation,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.settings.getSettings().token}`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue