From 441fc92e77f543baef10c3e675bd80b5cc6a1a0b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 19 Jun 2019 15:58:53 -0700 Subject: [PATCH] test: fix flaky test-worker-debug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Fixes: https://github.com/nodejs/node/issues/28299 Fixes: https://github.com/nodejs/node/issues/28106 --- test/parallel/parallel.status | 2 -- test/parallel/test-worker-debug.js | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 68a685395c43e4..3a70f6f03eb50f 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -21,8 +21,6 @@ test-worker-memory: PASS,FLAKY test-http2-client-upload: PASS,FLAKY # https://github.com/nodejs/node/issues/20750 test-http2-client-upload-reject: PASS,FLAKY -# https://github.com/nodejs/node/issues/28106 -test-worker-debug: PASS,FLAKY [$system==linux] diff --git a/test/parallel/test-worker-debug.js b/test/parallel/test-worker-debug.js index 2629af8cb32e37..1d7bb9bb185e66 100644 --- a/test/parallel/test-worker-debug.js +++ b/test/parallel/test-worker-debug.js @@ -240,11 +240,17 @@ async function testWaitForDisconnectInWorker(session, post) { }); await workerSession1.post('Runtime.runIfWaitingForDebugger'); + // Create the promises before sending the exit message to the Worker in order + // to avoid race conditions. + const disconnectPromise = + waitForEvent(workerSession1, 'NodeRuntime.waitingForDisconnect'); + const executionContextDestroyedPromise = + waitForEvent(workerSession2, 'Runtime.executionContextDestroyed'); worker.postMessage('resume'); - await waitForEvent(workerSession1, 'NodeRuntime.waitingForDisconnect'); + await disconnectPromise; post('NodeWorker.detach', { sessionId: sessionId1 }); - await waitForEvent(workerSession2, 'Runtime.executionContextDestroyed'); + await executionContextDestroyedPromise; await exitPromise;