Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c26747d

Browse files
addaleaxtargos
authored andcommittedSep 5, 2018
test: fix flaky test-worker-message-port-transfer-self
Look at the status of the `MessagePort` rather than relying on a timeout. PR-URL: #22658 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 1daa82a commit c26747d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed
 

‎test/parallel/test-worker-message-port-transfer-self.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const common = require('../common');
55
const assert = require('assert');
6+
const util = require('util');
67
const { MessageChannel } = require('worker_threads');
78

89
const { port1, port2 } = new MessageChannel();
@@ -25,9 +26,22 @@ assert.throws(common.mustCall(() => {
2526
// The failed transfer should not affect the ports in anyway.
2627
port2.onmessage = common.mustCall((message) => {
2728
assert.strictEqual(message, 2);
29+
30+
assert(util.inspect(port1).includes('active: true'), util.inspect(port1));
31+
assert(util.inspect(port2).includes('active: true'), util.inspect(port2));
32+
2833
port1.close();
2934

30-
setTimeout(common.mustNotCall('The communication channel is still open'),
31-
common.platformTimeout(1000)).unref();
35+
tick(10, () => {
36+
assert(util.inspect(port1).includes('active: false'), util.inspect(port1));
37+
assert(util.inspect(port2).includes('active: false'), util.inspect(port2));
38+
});
3239
});
3340
port1.postMessage(2);
41+
42+
function tick(n, cb) {
43+
if (n > 0)
44+
setImmediate(() => tick(n - 1, cb));
45+
else
46+
cb();
47+
}

0 commit comments

Comments
 (0)
Please sign in to comment.