Skip to content

Commit e7abde4

Browse files
itaysabatotargos
authored andcommitted
test: add a request-response test for MessageChannel
This commit adds a request-response test for MessageChannel. PR-URL: #21514 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3d3dbae commit e7abde4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/parallel/test-message-port.js

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ const { MessageChannel, MessagePort } = require('worker_threads');
1818
}));
1919
}
2020

21+
{
22+
const { port1, port2 } = new MessageChannel();
23+
24+
port1.onmessage = common.mustCall((message) => {
25+
assert.strictEqual(message, 4);
26+
port2.close(common.mustCall());
27+
});
28+
29+
port1.postMessage(2);
30+
31+
port2.onmessage = common.mustCall((message) => {
32+
port2.postMessage(message * 2);
33+
});
34+
}
35+
2136
{
2237
const { port1, port2 } = new MessageChannel();
2338

0 commit comments

Comments
 (0)