Skip to content

Commit

Permalink
test,worker: posting undefined/null message to message port
Browse files Browse the repository at this point in the history
Related: #26122

PR-URL: #26123
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
legendecas authored and addaleax committed Feb 17, 2019
1 parent 896b000 commit 665d13b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/parallel/test-worker-onmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ const { Worker, parentPort } = require('worker_threads');
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
const w = new Worker(__filename);
const expectation = [ 4, undefined, null ];
const actual = [];
w.on('message', common.mustCall((message) => {
assert.strictEqual(message, 4);
w.terminate();
}));
actual.push(message);
if (actual.length === expectation.length) {
assert.deepStrictEqual(expectation, actual);
w.terminate();
}
}, expectation.length));
w.postMessage(2);
} else {
parentPort.onmessage = common.mustCall((message) => {
parentPort.postMessage(message.data * 2);
parentPort.postMessage(undefined);
parentPort.postMessage(null);
});
}

0 comments on commit 665d13b

Please sign in to comment.