Skip to content

Commit

Permalink
fix: access bridge flaky tests (#627)
Browse files Browse the repository at this point in the history
* fix: flaky tests in access bridge
  • Loading branch information
kiremitrov123 authored Oct 10, 2024
1 parent d30d13d commit 1ae469b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
11 changes: 10 additions & 1 deletion platforms/access-bridge/src/pipeline/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Logger {
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
integrations: [nodeProfilingIntegration()],
integrations: this.getSentryIntegrations(),
environment: process.env.MODE || 'development',
release: process.env.APP_VERSION,
tracesSampleRate: SENTRY_TRACE_RATE,
Expand All @@ -33,6 +33,15 @@ class Logger {
}
}

// Include nodeProfilingIntegration only in production mode
private getSentryIntegrations() {
if (process.env.NODE_ENV === 'production') {
return [nodeProfilingIntegration()];
}

return [];
}

/**
* Logs an error message and sends it to Sentry if integrated.
* @param message - The error message to log.
Expand Down
1 change: 1 addition & 0 deletions platforms/access-bridge/src/pipeline/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class Middleware {
if (err instanceof Stripe.errors.StripeError) {
const accessBridgeError = handleStripeError(err);
sendErrors(res, accessBridgeError);
return;
}

if (isJWError(err)) {
Expand Down
5 changes: 3 additions & 2 deletions platforms/access-bridge/src/services/passport-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export class PassportService {
const now = new Date();
const token = jwt.sign(
{
// Sets expiration 3.6 seconds from now, rounded up to align with the next 300 ms interval for consistency.
exp: Math.ceil((now.getTime() + 3600) / 300) * 300,
// Sets expiration time to 3600 seconds (1 hour)
// The rounding is done to increase cacheability at the CDN level
exp: Math.ceil((now.getTime() / 1000 + 3600) / 300) * 300,
resource: path,
},
API_SECRET,
Expand Down
2 changes: 1 addition & 1 deletion platforms/access-bridge/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"noUnusedLocals": true,
"types": ["vitest/globals"],
},
"include": ["test/**/*", "src/**/*", "instrument.mjs"],
"include": ["test/**/*", "src/**/*"],
"exclude": ["node_modules", "build"],
}
5 changes: 5 additions & 0 deletions platforms/access-bridge/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ export default ({ mode, command }: ConfigEnv): UserConfigExport => {
globals: true,
environment: 'node',
setupFiles: 'test/vitest.setup.ts',
testTimeout: 10000,
chaiConfig: {
truncateThreshold: 1000,
},
// Switching to 'forks' fixes memory allocation issues and ensures worker processes terminate correctly.
// This is especially useful to avoid errors like SIGSEGV (segmentation faults) during tests.
// For more details, see: https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker
pool: 'forks',
},
});
};

0 comments on commit 1ae469b

Please sign in to comment.