test: fix timeouts when running worker tests with --worker

These tests have been added after the original workers PR and
time out when run inside a worker by themselves.
This is needed for enabling `--worker` tests in our regular CI.

Refs: https://github.com/nodejs/build/issues/1318

PR-URL: https://github.com/nodejs/node/pull/21791
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Anna Henningsen 2018-07-13 15:07:23 +02:00
parent 32cad739b1
commit 36cc5f5caf
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 8 additions and 4 deletions

View File

@ -7,9 +7,11 @@ const common = require('../common');
const assert = require('assert');
const worker = require('worker_threads');
const { Worker, isMainThread, parentPort } = worker;
const { Worker, parentPort } = worker;
if (isMainThread) {
// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
parent();
} else {
if (!parentPort) {

View File

@ -2,9 +2,11 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker, isMainThread, parentPort } = require('worker_threads');
const { Worker, parentPort } = require('worker_threads');
if (isMainThread) {
// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
const w = new Worker(__filename);
w.on('message', common.mustCall((message) => {
assert.strictEqual(message, 4);