Allow overriding WebSocket implementation and add flaky version for testing
This commit is contained in:
parent
74a8060246
commit
3ec6bd4d5b
1 changed files with 162 additions and 73 deletions
20
frontend/test-client/src/utils/flaky-fetch.ts
Normal file
20
frontend/test-client/src/utils/flaky-fetch.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { sleep } from "./sleep";
|
||||
|
||||
export const flakyFetchFactory =
|
||||
(jitterScaleInSeconds: number) =>
|
||||
async (
|
||||
input: string | URL | globalThis.Request,
|
||||
init?: RequestInit
|
||||
): Promise<Response> => {
|
||||
if (jitterScaleInSeconds > 0) {
|
||||
await sleep(Math.random() * jitterScaleInSeconds * 1000);
|
||||
}
|
||||
|
||||
const response = await fetch(input, init);
|
||||
|
||||
if (jitterScaleInSeconds > 0) {
|
||||
await sleep(Math.random() * jitterScaleInSeconds * 1000);
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
Loading…
Reference in a new issue