Skip to content

Commit 58adba5

Browse files
mydeaclaude
andauthored
test(nestjs): Fix flaky schedule instrumentation error tests (#25447)
The `@Interval` (and `@Cron`) handlers in `nestjs-basic` threw an identical error on every tick, and the `Dedupe` integration drops consecutive identical errors. Once earlier tests have killed the other erroring cron jobs, nothing interleaves, so only the first interval error is ever sent — often before the test starts listening — and `waitForError` times out. The handlers now include `Date.now()` in the error message so every tick produces a distinct error, and the tests only accept an error thrown after the test started. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d166870 commit 58adba5

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎dev-packages/e2e-tests/test-applications/nestjs-basic/src/schedule.service.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ export class ScheduleService {
77
constructor(private schedulerRegistry: SchedulerRegistry) {}
88

99
// @Cron error test (auto-instrumentation, no @SentryCron)
10+
// The timestamp keeps the Dedupe integration from dropping the error on repeated ticks.
1011
@Cron('*/5 * * * * *', { name: 'test-schedule-cron-error' })
1112
handleCronError() {
12-
throw new Error('Test error from schedule cron');
13+
throw new Error(`Test error from schedule cron ${Date.now()}`);
1314
}
1415

1516
// @Interval error test
1617
@Interval('test-schedule-interval-error', 2000)
1718
async handleIntervalError() {
18-
throw new Error('Test error from schedule interval');
19+
throw new Error(`Test error from schedule interval ${Date.now()}`);
1920
}
2021

2122
// @Timeout error test

‎dev-packages/e2e-tests/test-applications/nestjs-basic/tests/schedule-instrumentation.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { expect, test } from '@playwright/test';
22
import { waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils';
33

44
test('Sends exceptions to Sentry on error in @Cron decorated method', async ({ baseURL }) => {
5+
const testStart = Date.now();
56
const errorEventPromise = waitForError('nestjs-basic', event => {
7+
const thrownAt = event.exception?.values?.[0]?.value?.match(/^Test error from schedule cron (\d+)$/)?.[1];
68
return (
79
!event.type &&
8-
event.exception?.values?.[0]?.value === 'Test error from schedule cron' &&
10+
Number(thrownAt) >= testStart &&
911
event.exception?.values?.[0]?.mechanism?.type === 'auto.function.nestjs.cron'
1012
);
1113
});
@@ -23,10 +25,12 @@ test('Sends exceptions to Sentry on error in @Cron decorated method', async ({ b
2325
});
2426

2527
test('Sends exceptions to Sentry on error in @Interval decorated method', async ({ baseURL }) => {
28+
const testStart = Date.now();
2629
const errorEventPromise = waitForError('nestjs-basic', event => {
30+
const thrownAt = event.exception?.values?.[0]?.value?.match(/^Test error from schedule interval (\d+)$/)?.[1];
2731
return (
2832
!event.type &&
29-
event.exception?.values?.[0]?.value === 'Test error from schedule interval' &&
33+
Number(thrownAt) >= testStart &&
3034
event.exception?.values?.[0]?.mechanism?.type === 'auto.function.nestjs.interval'
3135
);
3236
});

0 commit comments

Comments
 (0)