Skip to content

Commit ef2ed71

Browse files
jasnelladuh95
authored andcommitted
test: rely less on duplicative common test harness utilities
There are several cleanups here that are not just style nits... 1. The `common.isMainThread` was just a passthrough to the `isMainThread` export on the worker_thread module. It's use was inconsistent and just obfuscated the fact that the test file depend on the `worker_threads` built-in. By eliminating it we simplify the test harness a bit and make it clearer which tests depend on the worker_threads check. 2. The `common.isDumbTerminal` is fairly unnecesary since that just wraps a public API check. 3. Several of the `common.skipIf....` checks were inconsistently used and really don't need to be separate utility functions. A key part of the motivation here is to work towards making more of the tests more self-contained and less reliant on the common test harness where possible. PR-URL: #56712 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent e654c8b commit ef2ed71

File tree

148 files changed

+672
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+672
-290
lines changed

‎test/abort/test-abort-backtrace.js‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
11
'use strict';
2-
constcommon=require('../common');
2+
require('../common');
33
constassert=require('assert');
44
constcp=require('child_process');
55

6+
functiongetPrintedStackTrace(stderr){
7+
constlines=stderr.split('\n');
8+
9+
letstate='initial';
10+
constresult={
11+
message: [],
12+
nativeStack: [],
13+
jsStack: [],
14+
};
15+
for(leti=0;i<lines.length;++i){
16+
constline=lines[i].trim();
17+
if(line.length===0){
18+
continue;// Skip empty lines.
19+
}
20+
21+
switch(state){
22+
case'initial':
23+
result.message.push(line);
24+
if(line.includes('Native stack trace')){
25+
state='native-stack';
26+
}else{
27+
result.message.push(line);
28+
}
29+
break;
30+
case'native-stack':
31+
if(line.includes('JavaScript stack trace')){
32+
state='js-stack';
33+
}else{
34+
result.nativeStack.push(line);
35+
}
36+
break;
37+
case'js-stack':
38+
result.jsStack.push(line);
39+
break;
40+
}
41+
}
42+
returnresult;
43+
}
44+
645
if(process.argv[2]==='child'){
746
process.abort();
847
}else{
948
constchild=cp.spawnSync(`${process.execPath}`,[`${__filename}`,'child']);
1049
conststderr=child.stderr.toString();
1150

1251
assert.strictEqual(child.stdout.toString(),'');
13-
const{ nativeStack, jsStack }=common.getPrintedStackTrace(stderr);
52+
const{ nativeStack, jsStack }=getPrintedStackTrace(stderr);
1453

1554
if(!nativeStack.every((frame,index)=>frame.startsWith(`${index+1}:`))){
1655
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
1756
}
1857

1958
// For systems that don't support backtraces, the native stack is
2059
// going to be empty.
21-
if(!common.isWindows&&nativeStack.length>0){
60+
if(process.platform!=='win32'&&nativeStack.length>0){
2261
const{ getBinaryPath }=require('../common/shared-lib-util');
2362
if(!nativeStack.some((frame)=>frame.includes(`[${getBinaryPath()}]`))){
2463
assert.fail(`Some native stack frame include the binary name:\n${stderr}`);

‎test/async-hooks/init-hooks.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22
// Flags: --expose-gc
33

4-
constcommon=require('../common');
4+
require('../common');
55
constassert=require('assert');
66
constasync_hooks=require('async_hooks');
7+
const{ isMainThread }=require('worker_threads');
78
constutil=require('util');
89
constprint=process._rawDebug;
910

@@ -161,7 +162,7 @@ class ActivityCollector{
161162
conststub={ uid,type: 'Unknown',handleIsObject: true,handle: {}};
162163
this._activities.set(uid,stub);
163164
returnstub;
164-
}elseif(!common.isMainThread){
165+
}elseif(!isMainThread){
165166
// Worker threads start main script execution inside of an AsyncWrap
166167
// callback, so we don't yield errors for these.
167168
returnnull;

‎test/async-hooks/test-crypto-pbkdf2.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

33
constcommon=require('../common');
4-
if(!common.hasCrypto)
4+
if(!common.hasCrypto){
55
common.skip('missing crypto');
6-
if(!common.isMainThread)
6+
}
7+
const{ isMainThread }=require('worker_threads');
8+
if(!isMainThread){
79
common.skip('Worker bootstrapping works differently -> different async IDs');
10+
}
811

912
constassert=require('assert');
1013
consttick=require('../common/tick');

‎test/async-hooks/test-crypto-randomBytes.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

33
constcommon=require('../common');
4-
if(!common.hasCrypto)
4+
if(!common.hasCrypto){
55
common.skip('missing crypto');
6-
if(!common.isMainThread)
6+
}
7+
const{ isMainThread }=require('worker_threads');
8+
if(!isMainThread){
79
common.skip('Worker bootstrapping works differently -> different async IDs');
10+
}
811

912
constassert=require('assert');
1013
consttick=require('../common/tick');

‎test/async-hooks/test-enable-disable.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ const assert = require('assert');
8787
consttick=require('../common/tick');
8888
constinitHooks=require('./init-hooks');
8989
const{ checkInvocations }=require('./hook-checks');
90+
const{ isMainThread }=require('worker_threads');
9091

91-
if(!common.isMainThread)
92+
if(!isMainThread)
9293
common.skip('Worker bootstrapping works differently -> different timing');
9394

9495
// Include "Unknown"s because hook2 will not be able to identify

‎test/async-hooks/test-fseventwrap.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ const initHooks = require('./init-hooks');
66
consttick=require('../common/tick');
77
const{ checkInvocations }=require('./hook-checks');
88
constfs=require('fs');
9+
const{ isMainThread }=require('worker_threads');
910

10-
if(!common.isMainThread)
11+
if(!isMainThread){
1112
common.skip('Worker bootstrapping works differently -> different async IDs');
13+
}
1214

13-
if(common.isIBMi)
15+
if(common.isIBMi){
1416
common.skip('IBMi does not support fs.watch()');
17+
}
1518

1619
consthooks=initHooks();
1720

‎test/async-hooks/test-fsreqcallback-readFile.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const tick = require('../common/tick');
66
constinitHooks=require('./init-hooks');
77
const{ checkInvocations }=require('./hook-checks');
88
constfs=require('fs');
9+
const{ isMainThread }=require('worker_threads');
910

10-
if(!common.isMainThread)
11+
if(!isMainThread){
1112
common.skip('Worker bootstrapping works differently -> different async IDs');
13+
}
1214

1315
consthooks=initHooks();
1416

‎test/async-hooks/test-getaddrinforeqwrap.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const tick = require('../common/tick');
66
constinitHooks=require('./init-hooks');
77
const{ checkInvocations }=require('./hook-checks');
88
constdns=require('dns');
9+
const{ isMainThread }=require('worker_threads');
910

10-
if(!common.isMainThread)
11+
if(!isMainThread){
1112
common.skip('Worker bootstrapping works differently -> different async IDs');
13+
}
1214

1315
consthooks=initHooks();
1416

‎test/async-hooks/test-getnameinforeqwrap.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const tick = require('../common/tick');
66
constinitHooks=require('./init-hooks');
77
const{ checkInvocations }=require('./hook-checks');
88
constdns=require('dns');
9+
const{ isMainThread }=require('worker_threads');
910

10-
if(!common.isMainThread)
11+
if(!isMainThread){
1112
common.skip('Worker bootstrapping works differently -> different async IDs');
13+
}
1214

1315
consthooks=initHooks();
1416

‎test/async-hooks/test-graph.signal.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

33
constcommon=require('../common');
4-
if(common.isWindows)
4+
if(common.isWindows){
55
common.skip('no signals on Windows');
6-
if(!common.isMainThread)
6+
}
7+
const{ isMainThread }=require('worker_threads');
8+
if(!isMainThread){
79
common.skip('No signal handling available in Workers');
10+
}
811

912
constinitHooks=require('./init-hooks');
1013
constverifyGraph=require('./verify-graph');

0 commit comments

Comments
(0)