Skip to content

Commit cb0ac22

Browse files
JPeer264claude
andauthored
test(node): Fix flaky unhandled rejection and uncaught exception tests (#21038)
closes #20697 closes [JS-2367](https://linear.app/getsentry/issue/JS-2367/flaky-ci-node-22-integration-tests-suitespublic) closes #20791 closes [JS-2429](https://linear.app/getsentry/issue/JS-2429) closes #20804 closes [JS-2435](https://linear.app/getsentry/issue/JS-2435) Follow up to: #21002 This one basically does the same, but changes it for all tests with that and outsources this into its own test util helper. --- Claude text: Extract `expectProcessToExit()` helper to consolidate watchdog timeout logic. Uses 3000ms to account for SDK's 2000ms shutdown timeout + buffer, fixing race conditions that caused flaky CI failures. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 52db40c commit cb0ac22

20 files changed

Lines changed: 62 additions & 82 deletions
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
@@ -11,9 +12,6 @@ process.on('uncaughtException', () => {
1112
// do nothing - this will prevent the Error below from closing this process before the timeout resolves
1213
});
1314

14-
setTimeout(() => {
15-
process.stdout.write("I'm alive!");
16-
process.exit(0);
17-
}, 500);
15+
expectProcessToExit();
1816

1917
throw new Error();

dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/mimic-native-behaviour-additional-listener-test-script.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
@@ -16,9 +17,6 @@ process.on('uncaughtException', () => {
1617
// do nothing - this will prevent the Error below from closing this process before the timeout resolves
1718
});
1819

19-
setTimeout(() => {
20-
process.stdout.write("I'm alive!");
21-
process.exit(0);
22-
}, 500);
20+
expectProcessToExit();
2321

2422
throw new Error();
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
@@ -12,11 +13,6 @@ const client = Sentry.init({
1213

1314
setupOtel(client);
1415

15-
setTimeout(() => {
16-
// This should not be called because the script throws before this resolves.
17-
// Using 3000ms to account for the SDK's 2000ms shutdown timeout + buffer.
18-
process.stdout.write("I'm alive!");
19-
process.exit(0);
20-
}, 3000);
16+
expectProcessToExit();
2117

2218
throw new Error();
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
67
});
78

89
setupOtel(client);
910

10-
setTimeout(() => {
11-
// This should not be called because the script throws before this resolves.
12-
// Using 3000ms to account for the SDK's 2000ms shutdown timeout + buffer.
13-
process.stdout.write("I'm alive!");
14-
process.exit(0);
15-
}, 3000);
11+
expectProcessToExit();
1612

1713
throw new Error();
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
@@ -8,9 +9,6 @@ const client = Sentry.init({
89

910
setupOtel(client);
1011

11-
setTimeout(() => {
12-
process.stdout.write("I'm alive!");
13-
process.exit(0);
14-
}, 500);
12+
expectProcessToExit();
1513

1614
Promise.reject('test rejection');
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
@@ -8,10 +9,6 @@ const client = Sentry.init({
89

910
setupOtel(client);
1011

11-
setTimeout(() => {
12-
// should not be called
13-
process.stdout.write("I'm alive!");
14-
process.exit(0);
15-
}, 500);
12+
expectProcessToExit();
1613

1714
Promise.reject('test rejection');
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
67
});
78

89
setupOtel(client);
910

10-
setTimeout(() => {
11-
process.stdout.write("I'm alive!");
12-
process.exit(0);
13-
}, 500);
11+
expectProcessToExit();
1412

1513
Promise.reject(new Error('test rejection'));
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
const Sentry = require('@sentry/node-core');
22
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
34

45
const client = Sentry.init({
56
dsn: 'https://public@dsn.ingest.sentry.io/1337',
67
});
78

89
setupOtel(client);
910

10-
setTimeout(() => {
11-
process.stdout.write("I'm alive!");
12-
process.exit(0);
13-
}, 500);
11+
expectProcessToExit();
1412

1513
Promise.reject('test rejection');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Sets a watchdog timer that prints "I'm alive!" and exits if the process
3+
* doesn't terminate before the timeout. Uses 3000ms to account for the
4+
* SDK's 2000ms shutdown timeout + buffer.
5+
*/
6+
function expectProcessToExit() {
7+
setTimeout(() => {
8+
process.stdout.write("I'm alive!");
9+
process.exit(0);
10+
}, 3000);
11+
}
12+
13+
module.exports = { expectProcessToExit };
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Sentry = require('@sentry/node');
2+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
23

34
Sentry.init({
45
dsn: 'https://public@dsn.ingest.sentry.io/1337',
@@ -8,9 +9,6 @@ process.on('uncaughtException', () => {
89
// do nothing - this will prevent the Error below from closing this process before the timeout resolves
910
});
1011

11-
setTimeout(() => {
12-
process.stdout.write("I'm alive!");
13-
process.exit(0);
14-
}, 500);
12+
expectProcessToExit();
1513

1614
throw new Error();

0 commit comments

Comments
 (0)