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 <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
This commit is contained in:
Rich Trott committed 2018-07-24 13:27:55 -07:00
1 parent 945324050b
commit f93a19b428
1 file changed
+6 -2
@@ -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'));