From 2dec0f98310bcf996550cfbd3398eb983ab93e16 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. PR-URL: https://github.com/nodejs/node/pull/28307 Fixes: https://github.com/nodejs/node/issues/28299 Fixes: https://github.com/nodejs/node/issues/28106 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Yongsheng Zhang --- 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 68a685395c..3a70f6f03e 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 2629af8cb3..1d7bb9bb18 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;