From 71e1602fb8542700c53b068f2120977b9f868753 Mon Sep 17 00:00:00 2001 From: itaysabato Date: Mon, 25 Jun 2018 10:13:01 +0300 Subject: [PATCH] test: add a request-response test for MessageChannel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a request-response test for MessageChannel. PR-URL: https://github.com/nodejs/node/pull/21514 Reviewed-By: Michaƫl Zasso Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: James M Snell --- test/parallel/test-message-port.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/parallel/test-message-port.js b/test/parallel/test-message-port.js index fe88126d044c2b..2d321611ec7758 100644 --- a/test/parallel/test-message-port.js +++ b/test/parallel/test-message-port.js @@ -18,6 +18,21 @@ const { MessageChannel, MessagePort } = require('worker_threads'); })); } +{ + const { port1, port2 } = new MessageChannel(); + + port1.onmessage = common.mustCall((message) => { + assert.strictEqual(message, 4); + port2.close(common.mustCall()); + }); + + port1.postMessage(2); + + port2.onmessage = common.mustCall((message) => { + port2.postMessage(message * 2); + }); +} + { const { port1, port2 } = new MessageChannel();