Adjust endpoint timeout failures (#9114)

This commit is contained in:
Jaco 2023-03-06 10:58:54 +02:00 committed by GitHub
parent 80af84540c
commit 1bfd12d07e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,32 +38,8 @@ describe('check endpoints', (): void => {
ws: value ws: value
})) }))
.filter((v): v is Endpoint => !!v.ws); .filter((v): v is Endpoint => !!v.ws);
let completed = 0;
let errored = 0;
let websocket: WebSocket | null = null; let websocket: WebSocket | null = null;
let closeTimerId: ReturnType<typeof setTimeout> | null = null;
afterEach((): void => {
completed++;
if (websocket) {
websocket.onclose = noopHandler;
websocket.onerror = noopHandler;
websocket.onopen = noopHandler;
websocket.onmessage = noopHandler;
try {
websocket.close();
} catch (e) {
console.error((e as Error).message);
}
websocket = null;
}
if (completed === checks.length) {
process.exit(errored);
}
});
for (const { name, ws: endpoint } of checks) { for (const { name, ws: endpoint } of checks) {
it(`${name} @ ${endpoint}`, async (): Promise<void> => { it(`${name} @ ${endpoint}`, async (): Promise<void> => {
@ -102,13 +78,37 @@ describe('check endpoints', (): void => {
reject(e); reject(e);
} }
}; };
closeTimerId = setTimeout(
() => {
closeTimerId = null;
reject(new Error('Connection timeout'));
},
TIMEOUT
);
}) })
) )
.catch((e) => { .finally(() => {
errored++; if (closeTimerId) {
clearTimeout(closeTimerId);
closeTimerId = null;
}
throw e; if (websocket) {
websocket.onclose = noopHandler;
websocket.onerror = noopHandler;
websocket.onopen = noopHandler;
websocket.onmessage = noopHandler;
try {
websocket.close();
} catch (e) {
console.error((e as Error).message);
}
websocket = null;
}
}); });
}, TIMEOUT); });
} }
}); });