Skip to content

Commit 3d2b4d6

Browse files
JPeer264claude
andauthored
test(node): Fix flaky thread-blocked-native worker thread test (#21026)
closes #20703 closes [JS-2371](https://linear.app/getsentry/issue/JS-2371/flaky-ci-node-24-ts-38-integration-tests-suitesthread-blocked) closes #20676 closes [JS-2358](https://linear.app/getsentry/issue/JS-2358/flaky-ci-node-20-integration-tests-suitesthread-blocked-nativetestts) This was the best guess from Claude. I tried to reproduce this locally but failed. I used Docker to change the resources and lowered the CPU and memory on a reproduction. But I never reproduced the same failing state. However, this new approach is faster (Claude was very proud of that) as it is not waiting 10s, before it starts, but starts as soon as everything is set up - that also never failed locally - so it is a shot in the dark 🤞 --- Claude message: The worker thread test was flaky on CI because it used a fixed 10s delay before blocking the event loop. On slow CI machines, the Sentry SDK polling might not have fully started within that time window. Replace the fixed delay with active polling that waits for the ThreadBlocked integration to be installed, then waits 1s for polling to start before blocking. This makes the test: - More reliable: actively verifies Sentry is ready instead of hoping - Faster: ~3s vs ~12s locally - Has a 30s timeout as a safety net Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9bd04f0 commit 3d2b4d6

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

  • dev-packages/node-integration-tests/suites/thread-blocked-native
Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1+
import * as Sentry from '@sentry/node';
12
import { longWork } from './long-work.js';
23

3-
setTimeout(() => {
4+
// Wait for Sentry to be fully initialized before blocking.
5+
// This prevents flaky tests on slow CI where the fixed 10s delay
6+
// might fire before the native polling has started.
7+
async function waitForSentryReady(timeoutMs = 30_000) {
8+
const start = Date.now();
9+
10+
while (Date.now() - start < timeoutMs) {
11+
const client = Sentry.getClient();
12+
if (client?.getIntegrationByName('ThreadBlocked')) {
13+
// Integration is installed, wait a bit for polling to start
14+
// (polling starts via setImmediate in afterAllSetup)
15+
await new Promise(resolve => setTimeout(resolve, 1000));
16+
return;
17+
}
18+
await new Promise(resolve => setTimeout(resolve, 100));
19+
}
20+
21+
// Timeout - the test will fail anyway since no event will be sent
22+
}
23+
24+
waitForSentryReady().then(() => {
425
longWork();
5-
}, 10_000);
26+
});

0 commit comments

Comments
 (0)