Skip to content

Commit f46536b

Browse files
addaleaxtargos
authored andcommitted
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: nodejs/build#1318 PR-URL: #21791 Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent c02fb88 commit f46536b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

test/parallel/test-worker-exit-code.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ const common = require('../common');
77

88
const assert = require('assert');
99
const worker = require('worker_threads');
10-
const { Worker, isMainThread, parentPort } = worker;
10+
const { Worker, parentPort } = worker;
1111

12-
if (isMainThread) {
12+
// Do not use isMainThread so that this test itself can be run inside a Worker.
13+
if (!process.env.HAS_STARTED_WORKER) {
14+
process.env.HAS_STARTED_WORKER = 1;
1315
parent();
1416
} else {
1517
if (!parentPort) {

test/parallel/test-worker-onmessage.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
'use strict';
33
const common = require('../common');
44
const assert = require('assert');
5-
const { Worker, isMainThread, parentPort } = require('worker_threads');
5+
const { Worker, parentPort } = require('worker_threads');
66

7-
if (isMainThread) {
7+
// Do not use isMainThread so that this test itself can be run inside a Worker.
8+
if (!process.env.HAS_STARTED_WORKER) {
9+
process.env.HAS_STARTED_WORKER = 1;
810
const w = new Worker(__filename);
911
w.on('message', common.mustCall((message) => {
1012
assert.strictEqual(message, 4);

0 commit comments

Comments
 (0)