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 28, 2020
1 parent ad2fdd5 commit c5e0615
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
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
Expand Up @@ -3,17 +3,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 c5e0615

Please sign in to comment.