From 623ef4961b4273100f2732a210f2c57e9e3dee82 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 PR-URL: https://github.com/nodejs/node/pull/21893 Reviewed-By: Anna Henningsen Reviewed-By: Yuta Hiroto --- 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'));