From d6f37e6e1bcc8641cfe4fda1aae79b1c246697df Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 19 Jul 2018 12:17:11 -0700 Subject: [PATCH] test: address flaky worker test Make test/parallel/test-worker-message-port-transfer-closed.js more reliable by counting ticks rather than using a single setTimeout(). Fixes: https://github.com/nodejs/node/issues/21892 --- test/parallel/test-worker-message-port-transfer-closed.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-worker-message-port-transfer-closed.js b/test/parallel/test-worker-message-port-transfer-closed.js index 435a3789fca724..32de1af1f97a81 100644 --- a/test/parallel/test-worker-message-port-transfer-closed.js +++ b/test/parallel/test-worker-message-port-transfer-closed.js @@ -50,5 +50,9 @@ testSingle(port1, port2); port2.close(common.mustCall(testBothClosed)); testBothClosed(); -setTimeout(common.mustNotCall('The communication channel is still open'), - common.platformTimeout(1000)).unref(); +function tickUnref(n, fn) { + if (n === 0) return fn(); + setImmediate(tickUnref, n - 1, fn).unref(); +} + +tickUnref(10, common.mustNotCall('The communication channel is still open'));