From 9db7dfc019d99106ca1116be859468f6793078ea Mon Sep 17 00:00:00 2001 From: d46 Date: Fri, 18 Oct 2024 14:20:00 +0200 Subject: [PATCH] fix(chore): Run tests serial && retry mechanism for application bootstrap --- e2e-common/vitest.config.mts | 3 +++ packages/testing/src/test-server.ts | 26 +++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/e2e-common/vitest.config.mts b/e2e-common/vitest.config.mts index 25bdd44b5e..a8a0f4e308 100644 --- a/e2e-common/vitest.config.mts +++ b/e2e-common/vitest.config.mts @@ -10,6 +10,9 @@ export default defineConfig({ * automatically fail for going over the 5 second default timeout. */ testTimeout: process.env.E2E_DEBUG ? 1800 * 1000 : process.env.CI ? 30 * 1000 : 15 * 1000, + sequence: { + concurrent: false, + }, // threads: false, // singleThread: true, // reporters: ['verbose'], diff --git a/packages/testing/src/test-server.ts b/packages/testing/src/test-server.ts index 963132b73b..82e01f4159 100644 --- a/packages/testing/src/test-server.ts +++ b/packages/testing/src/test-server.ts @@ -1,7 +1,7 @@ import { INestApplication } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { DefaultLogger, JobQueueService, Logger, VendureConfig } from '@vendure/core'; -import { preBootstrapConfig, configureSessionCookies } from '@vendure/core/dist/bootstrap'; +import { configureSessionCookies, preBootstrapConfig } from '@vendure/core/dist/bootstrap'; import { populateForTesting } from './data-population/populate-for-testing'; import { getInitializerFor } from './initializers/initializers'; @@ -40,7 +40,28 @@ export class TestServer { } catch (e: any) { throw e; } - await this.bootstrap(); + await this.initializeApp(); + } + + async initializeApp() { + const maxRetries = 50; + let attempt = 0; + + while (attempt < maxRetries) { + try { + await this.bootstrap(); + break; + } catch (error) { + attempt++; + if (attempt < maxRetries) { + const backoffTime = Math.pow(2, attempt) * 10; // Exponential backoff + await new Promise(resolve => setTimeout(resolve, backoffTime)); + } else { + console.error(error); + break; + } + } + } } /** @@ -132,7 +153,6 @@ export class TestServer { DefaultLogger.restoreOriginalLogLevel(); return app; } catch (e: any) { - console.log(e); throw e; } }