diff --git a/packages/worker/src/tests/TestConfiguration.ts b/packages/worker/src/tests/TestConfiguration.ts index 5c4063c5ca..b13bdefa0e 100644 --- a/packages/worker/src/tests/TestConfiguration.ts +++ b/packages/worker/src/tests/TestConfiguration.ts @@ -20,7 +20,6 @@ import { auth, constants, env as coreEnv, - context, utils, DEFAULT_TENANT_ID, } from "@budibase/backend-core" @@ -34,6 +33,25 @@ enum Mode { SELF = "self", } +export async function retry any>( + fn: T, + maxTry: number = 5, + retryCount = 1 +): Promise>> { + const currRetry = typeof retryCount === "number" ? retryCount : 1 + try { + const result = await fn() + return result + } catch (e) { + console.log(`Retry ${currRetry} failed.`) + if (currRetry > maxTry) { + console.log(`All ${maxTry} retry attempts exhausted`) + throw e + } + return retry(fn, maxTry, currRetry + 1) + } +} + class TestConfiguration { server: any request: any @@ -119,7 +137,8 @@ class TestConfiguration { async beforeAll() { this.#tenantId = `tenant-${utils.newid()}` - await this.createDefaultUser() + // Running tests in parallel causes issues creating the globaldb twice. This ensures the db is properly created before starting + await retry(async () => await this.createDefaultUser()) await this.createSession(this.defaultUser!) await tenancy.doInTenant(this.#tenantId, async () => {