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 <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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

Lines changed: 15 additions & 0 deletions
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)