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 54474a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 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
26 changes: 23 additions & 3 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 = 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;
}
}
}
}

/**
Expand Down Expand Up @@ -132,7 +153,6 @@ export class TestServer {
DefaultLogger.restoreOriginalLogLevel();
return app;
} catch (e: any) {
console.log(e);
throw e;
}
}
Expand Down

0 comments on commit 54474a5

Please sign in to comment.