Change fetch implementation passing

This commit is contained in:
Andras Schmelczer 2025-03-20 21:18:22 +00:00
commit 198ac93c8c
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 23 additions and 16 deletions

View file

@ -25,23 +25,24 @@ export class MockAgent extends MockClient {
}
public async init(): Promise<void> {
await super.init();
await super.init(
// flaky fetch implementation to use during testing
async (
input: string | URL | globalThis.Request,
init?: RequestInit
): Promise<Response> => {
await sleep(Math.random() * this.jitterScaleInSeconds * 1000);
const response = await fetch(input, init);
await sleep(Math.random() * this.jitterScaleInSeconds * 1000);
return response;
}
);
assert(
(await this.client.checkConnection()).isSuccessful,
"Connection check failed"
);
this.client.fetchImplementation = async (
input: string | URL | globalThis.Request,
init?: RequestInit
): Promise<Response> => {
await sleep(Math.random() * this.jitterScaleInSeconds * 1000);
const response = await fetch(input, init);
await sleep(Math.random() * this.jitterScaleInSeconds * 1000);
return response;
};
this.client.logger.addOnMessageListener((logLine: LogLine) => {
const state = this.client.getSettings().isSyncEnabled
? "(online) "