Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions dev-packages/node-core-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import type { Event } from '@sentry/core';
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';

/** Avoid flakes on slow CI: fixed sleeps can fire before the child process has finished exiting. */
async function waitForChildExit(childHasExited: () => boolean, timeoutMs = 30_000): Promise<void> {
const start = Date.now();
while (!childHasExited()) {
if (Date.now() - start > timeoutMs) {
throw new Error('Timed out waiting for child process to exit');
}
await new Promise<void>(resolve => setTimeout(resolve, 100));
}
}

const ANR_EVENT = {
// Ensure we have context
contexts: {
Expand Down Expand Up @@ -178,15 +189,15 @@ describe('should report ANR when event loop blocked', { timeout: 90_000 }, () =>
test('should exit', async () => {
const runner = createRunner(__dirname, 'should-exit.js').start();

await new Promise(resolve => setTimeout(resolve, 5_000));
await waitForChildExit(() => runner.childHasExited());

expect(runner.childHasExited()).toBe(true);
});

test('should exit forced', async () => {
const runner = createRunner(__dirname, 'should-exit-forced.js').start();

await new Promise(resolve => setTimeout(resolve, 5_000));
await waitForChildExit(() => runner.childHasExited());

expect(runner.childHasExited()).toBe(true);
});
Expand Down
Loading