From 051089d46668e017736e84fe6a9a6b85e7b419b8 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 6 Aug 2024 11:10:24 +0200 Subject: [PATCH] Merge pull request #19779 from overleaf/jpa-e2e-retries [server-pro] tests: add 5 retries to host-admin requests GitOrigin-RevId: 1a1df58c37b14139e09c66d3306d04b4bc667690 --- server-ce/test/helpers/hostAdminClient.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server-ce/test/helpers/hostAdminClient.ts b/server-ce/test/helpers/hostAdminClient.ts index 6dd0b1ff7e..1246d5a1e3 100644 --- a/server-ce/test/helpers/hostAdminClient.ts +++ b/server-ce/test/helpers/hostAdminClient.ts @@ -35,7 +35,18 @@ async function fetchJSON( if (init?.body) { init.headers = { 'Content-Type': 'application/json' } } - const res = await fetch(input, init) + let res + for (let attempt = 0; attempt < 5; attempt++) { + try { + res = await fetch(input, init) + break + } catch { + await sleep(3_000) + } + } + if (!res) { + res = await fetch(input, init) + } const { error, stdout, stderr, ...rest } = await res.json() if (error) { console.error(input, init, 'failed:', error) @@ -73,3 +84,9 @@ export async function getRedisKeys() { }) return stdout.split('\n') } + +async function sleep(ms: number) { + return new Promise(resolve => { + setTimeout(resolve, ms) + }) +}