Skip to content

Commit

Permalink
fix(chore): Run tests serial && retry mechanism for application boots…
Browse files Browse the repository at this point in the history
…trap
  • Loading branch information
d46 committed Oct 18, 2024
1 parent 4c6a397 commit 1b2b095
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions e2e-common/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
25 changes: 23 additions & 2 deletions packages/testing/src/test-server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -40,7 +40,28 @@ export class TestServer {
} catch (e: any) {
throw e;
}
await this.bootstrap();
await this.initializeApp();
}

async initializeApp() {
const maxRetries = 5;
let attempt = 0;

while (attempt < maxRetries) {
try {
await this.bootstrap();
} catch (error) {
attempt++;
console.error(`Bootstrap failed on attempt ${attempt}:`, error);

if (attempt < maxRetries) {
const backoffTime = Math.pow(2, attempt) * 10; // Exponential backoff
await new Promise(resolve => setTimeout(resolve, backoffTime));
} else {
console.error('Max retries reached. Failed to bootstrap the application.');
}
}
}
}

/**
Expand Down

0 comments on commit 1b2b095

Please sign in to comment.