Skip to content

Commit

Permalink
test: refactor test-worker
Browse files Browse the repository at this point in the history
PR-URL: #32509
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
  • Loading branch information
himself65 authored and targos committed Apr 11, 2020
1 parent 3b5c4fb commit 4ffa138
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions test/parallel/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ const common = require('../common');
const assert = require('assert');
const { Worker, isMainThread, parentPort } = require('worker_threads');

const kTestString = 'Hello, world!';

if (isMainThread) {
const w = new Worker(__filename);
w.on('message', common.mustCall((message) => {
assert.strictEqual(message, 'Hello, world!');
assert.strictEqual(message, kTestString);
}));
} else {
setImmediate(() => {
process.nextTick(() => {
parentPort.postMessage('Hello, world!');
parentPort.postMessage(kTestString);
});
});
}
6 changes: 3 additions & 3 deletions test/parallel/test-worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { mustCall } from '../common/index.mjs';
import assert from 'assert';
import { Worker, isMainThread, parentPort } from 'worker_threads';

const TEST_STRING = 'Hello, world!';
const kTestString = 'Hello, world!';

if (isMainThread) {
const w = new Worker(new URL(import.meta.url));
w.on('message', mustCall((message) => {
assert.strictEqual(message, TEST_STRING);
assert.strictEqual(message, kTestString);
}));
} else {
setImmediate(() => {
process.nextTick(() => {
parentPort.postMessage(TEST_STRING);
parentPort.postMessage(kTestString);
});
});
}

0 comments on commit 4ffa138

Please sign in to comment.