Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef2ed71

Browse filesBrowse 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 <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent e654c8b commit ef2ed71
Copy full SHA for ef2ed71

File tree

Expand file treeCollapse file tree

148 files changed

+672
-290
lines changed
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

148 files changed

+672
-290
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/abort/test-abort-backtrace.js
+42-3Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55

6+
function getPrintedStackTrace(stderr) {
7+
const lines = stderr.split('\n');
8+
9+
let state = 'initial';
10+
const result = {
11+
message: [],
12+
nativeStack: [],
13+
jsStack: [],
14+
};
15+
for (let i = 0; i < lines.length; ++i) {
16+
const line = 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+
return result;
43+
}
44+
645
if (process.argv[2] === 'child') {
746
process.abort();
847
} else {
948
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
1049
const stderr = 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}`);
Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/init-hooks.js
+3-2Lines 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-
const common = require('../common');
4+
require('../common');
55
const assert = require('assert');
66
const async_hooks = require('async_hooks');
7+
const { isMainThread } = require('worker_threads');
78
const util = require('util');
89
const print = process._rawDebug;
910

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

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-crypto-pbkdf2.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

33
const common = 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
const assert = require('assert');
1013
const tick = require('../common/tick');
Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-crypto-randomBytes.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

33
const common = 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
const assert = require('assert');
1013
const tick = require('../common/tick');
Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-enable-disable.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ const assert = require('assert');
8787
const tick = require('../common/tick');
8888
const initHooks = 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
Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-fseventwrap.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ const initHooks = require('./init-hooks');
66
const tick = require('../common/tick');
77
const { checkInvocations } = require('./hook-checks');
88
const fs = 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
const hooks = initHooks();
1720

Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-fsreqcallback-readFile.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const tick = require('../common/tick');
66
const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88
const fs = 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
const hooks = initHooks();
1416

Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-getaddrinforeqwrap.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const tick = require('../common/tick');
66
const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88
const dns = 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
const hooks = initHooks();
1416

Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-getnameinforeqwrap.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const tick = require('../common/tick');
66
const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88
const dns = 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
const hooks = initHooks();
1416

Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-graph.signal.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

33
const common = 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
const initHooks = require('./init-hooks');
1013
const verifyGraph = require('./verify-graph');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.