Skip to content

Commit c44db7f

Browse files
addaleaxtargos
authored andcommitted
test: fix flaky test-worker-debug
Address a race condition in the test; the Worker’s exit events may have been not recorded because the Worker exited before the listeners were attached. Fix the by attaching the event listeners before telling the Worker to exit. PR-URL: #28307 Fixes: #28299 Fixes: #28106 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent dd53e6a commit c44db7f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

test/parallel/parallel.status

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ test-worker-memory: PASS,FLAKY
2121
test-http2-client-upload: PASS,FLAKY
2222
# https://github.com/nodejs/node/issues/20750
2323
test-http2-client-upload-reject: PASS,FLAKY
24-
# https://github.com/nodejs/node/issues/28106
25-
test-worker-debug: PASS,FLAKY
2624

2725
[$system==linux]
2826

test/parallel/test-worker-debug.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,17 @@ async function testWaitForDisconnectInWorker(session, post) {
240240
});
241241
await workerSession1.post('Runtime.runIfWaitingForDebugger');
242242

243+
// Create the promises before sending the exit message to the Worker in order
244+
// to avoid race conditions.
245+
const disconnectPromise =
246+
waitForEvent(workerSession1, 'NodeRuntime.waitingForDisconnect');
247+
const executionContextDestroyedPromise =
248+
waitForEvent(workerSession2, 'Runtime.executionContextDestroyed');
243249
worker.postMessage('resume');
244250

245-
await waitForEvent(workerSession1, 'NodeRuntime.waitingForDisconnect');
251+
await disconnectPromise;
246252
post('NodeWorker.detach', { sessionId: sessionId1 });
247-
await waitForEvent(workerSession2, 'Runtime.executionContextDestroyed');
253+
await executionContextDestroyedPromise;
248254

249255
await exitPromise;
250256

0 commit comments

Comments
 (0)