@@ -2,6 +2,17 @@ import type { Event } from '@sentry/core';
22import { afterAll , describe , expect , test } from 'vitest' ;
33import { cleanupChildProcesses , createRunner } from '../../utils/runner' ;
44
5+ /** Avoid flakes on slow CI: fixed sleeps can fire before the child process has finished exiting. */
6+ async function waitForChildExit ( childHasExited : ( ) => boolean , timeoutMs = 30_000 ) : Promise < void > {
7+ const start = Date . now ( ) ;
8+ while ( ! childHasExited ( ) ) {
9+ if ( Date . now ( ) - start > timeoutMs ) {
10+ throw new Error ( 'Timed out waiting for child process to exit' ) ;
11+ }
12+ await new Promise < void > ( resolve => setTimeout ( resolve , 100 ) ) ;
13+ }
14+ }
15+
516const ANR_EVENT = {
617 // Ensure we have context
718 contexts : {
@@ -178,15 +189,15 @@ describe('should report ANR when event loop blocked', { timeout: 90_000 }, () =>
178189 test ( 'should exit' , async ( ) => {
179190 const runner = createRunner ( __dirname , 'should-exit.js' ) . start ( ) ;
180191
181- await new Promise ( resolve => setTimeout ( resolve , 5_000 ) ) ;
192+ await waitForChildExit ( ( ) => runner . childHasExited ( ) ) ;
182193
183194 expect ( runner . childHasExited ( ) ) . toBe ( true ) ;
184195 } ) ;
185196
186197 test ( 'should exit forced' , async ( ) => {
187198 const runner = createRunner ( __dirname , 'should-exit-forced.js' ) . start ( ) ;
188199
189- await new Promise ( resolve => setTimeout ( resolve , 5_000 ) ) ;
200+ await waitForChildExit ( ( ) => runner . childHasExited ( ) ) ;
190201
191202 expect ( runner . childHasExited ( ) ) . toBe ( true ) ;
192203 } ) ;
0 commit comments