test: rely less on duplicative common test harness utilities · nodejs/node@1795202 · GitHub
Skip to content

Commit 1795202

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 <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 5be29a2 commit 1795202

148 files changed

Lines changed: 671 additions & 290 deletions

File tree

Some content is hidden

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

test/abort/test-abort-backtrace.js

Lines changed: 42 additions & 3 deletions

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-
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;

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
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');

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
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');

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
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

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
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

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
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

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
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

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
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

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

Lines changed: 5 additions & 2 deletions

0 commit comments

Comments
 (0)