Skip to content

Commit

Permalink
test: fix timeouts when running worker tests with --worker
Browse files Browse the repository at this point in the history
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: nodejs/build#1318

PR-URL: #21791
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
addaleax authored and targos committed Jul 14, 2018
1 parent c02fb88 commit f46536b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions test/parallel/test-worker-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-worker-onmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f46536b

Please sign in to comment.