diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-09-02 17:30:45 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-09-05 12:03:52 +0200 |
commit | b3eb3a19ade16b9a5aeef75399a6a91a07313f49 (patch) | |
tree | 7f692cf177c3b42120ff6eb98f68f9543963f6c1 /test/parallel/test-worker-message-port-transfer-self.js | |
parent | caf8e7a49d60ca4230e5ec4417c2ef2060c94ee3 (diff) | |
download | android-node-v8-b3eb3a19ade16b9a5aeef75399a6a91a07313f49.tar.gz android-node-v8-b3eb3a19ade16b9a5aeef75399a6a91a07313f49.tar.bz2 android-node-v8-b3eb3a19ade16b9a5aeef75399a6a91a07313f49.zip |
test: fix flaky test-worker-message-port-transfer-self
Look at the status of the `MessagePort` rather than
relying on a timeout.
PR-URL: https://github.com/nodejs/node/pull/22658
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-worker-message-port-transfer-self.js')
-rw-r--r-- | test/parallel/test-worker-message-port-transfer-self.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/test/parallel/test-worker-message-port-transfer-self.js b/test/parallel/test-worker-message-port-transfer-self.js index 1855023cdf..4fe12c0a88 100644 --- a/test/parallel/test-worker-message-port-transfer-self.js +++ b/test/parallel/test-worker-message-port-transfer-self.js @@ -3,6 +3,7 @@ const common = require('../common'); const assert = require('assert'); +const util = require('util'); const { MessageChannel } = require('worker_threads'); const { port1, port2 } = new MessageChannel(); @@ -25,9 +26,22 @@ assert.throws(common.mustCall(() => { // The failed transfer should not affect the ports in anyway. port2.onmessage = common.mustCall((message) => { assert.strictEqual(message, 2); + + assert(util.inspect(port1).includes('active: true'), util.inspect(port1)); + assert(util.inspect(port2).includes('active: true'), util.inspect(port2)); + port1.close(); - setTimeout(common.mustNotCall('The communication channel is still open'), - common.platformTimeout(1000)).unref(); + tick(10, () => { + assert(util.inspect(port1).includes('active: false'), util.inspect(port1)); + assert(util.inspect(port2).includes('active: false'), util.inspect(port2)); + }); }); port1.postMessage(2); + +function tick(n, cb) { + if (n > 0) + setImmediate(() => tick(n - 1, cb)); + else + cb(); +} |