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 <me@jonathanmoss.me> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent c02fb88 commit f46536b

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

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

88
constassert=require('assert');
99
constworker=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‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
'use strict';
33
constcommon=require('../common');
44
constassert=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
constw=newWorker(__filename);
911
w.on('message',common.mustCall((message)=>{
1012
assert.strictEqual(message,4);

0 commit comments

Comments
 (0)