Skip to content

Commit ed05d9a

Browse files
addaleaxtargos
authored andcommitted
test,tools: enable running tests under workers
Enable running tests inside workers by passing `--worker` to `tools/test.py`. A number of tests are marked as skipped, or have been slightly altered to fit the different environment. PR-URL: #20876 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent 9ad42b7 commit ed05d9a

File tree

84 files changed

+274
-37
lines changed

Some content is hidden

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

84 files changed

+274
-37
lines changed

test/async-hooks/init-hooks.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
// Flags: --expose-gc
33

4-
require('../common');
4+
const common = require('../common');
55
const assert = require('assert');
66
const async_hooks = require('async_hooks');
77
const util = require('util');
@@ -162,6 +162,10 @@ class ActivityCollector {
162162
const stub = { uid, type: 'Unknown', handleIsObject: true };
163163
this._activities.set(uid, stub);
164164
return stub;
165+
} else if (!common.isMainThread) {
166+
// Worker threads start main script execution inside of an AsyncWrap
167+
// callback, so we don't yield errors for these.
168+
return null;
165169
} else {
166170
const err = new Error(`Found a handle whose ${hook}` +
167171
' hook was invoked but not its init hook');

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

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
6+
if (!common.isMainThread)
7+
common.skip('Worker bootstrapping works differently -> different async IDs');
68

79
const assert = require('assert');
810
const tick = require('./tick');

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

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
6+
if (!common.isMainThread)
7+
common.skip('Worker bootstrapping works differently -> different async IDs');
68

79
const assert = require('assert');
810
const tick = require('./tick');

test/async-hooks/test-emit-before-after.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const spawnSync = require('child_process').spawnSync;
77
const async_hooks = require('internal/async_hooks');
88
const initHooks = require('./init-hooks');
99

10+
if (!common.isMainThread)
11+
common.skip('Worker bootstrapping works differently -> different async IDs');
12+
1013
switch (process.argv[2]) {
1114
case 'test_invalid_async_id':
1215
async_hooks.emitBefore(-2, 1);

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

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ const assert = require('assert');
8888
const tick = require('./tick');
8989
const initHooks = require('./init-hooks');
9090
const { checkInvocations } = require('./hook-checks');
91+
92+
if (!common.isMainThread)
93+
common.skip('Worker bootstrapping works differently -> different timing');
94+
9195
// Include "Unknown"s because hook2 will not be able to identify
9296
// the type of the first Immediate since it will miss its `init` invocation.
9397
const types = [ 'Immediate', 'Unknown' ];

test/async-hooks/test-fseventwrap.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33

44
const assert = require('assert');
55
const initHooks = require('./init-hooks');
66
const tick = require('./tick');
77
const { checkInvocations } = require('./hook-checks');
88
const fs = require('fs');
99

10+
if (!common.isMainThread)
11+
common.skip('Worker bootstrapping works differently -> different async IDs');
12+
1013
const hooks = initHooks();
1114

1215
hooks.enable();

test/async-hooks/test-fsreqwrap-readFile.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88
const fs = require('fs');
99

10+
if (!common.isMainThread)
11+
common.skip('Worker bootstrapping works differently -> different async IDs');
12+
1013
const hooks = initHooks();
1114

1215
hooks.enable();

test/async-hooks/test-getaddrinforeqwrap.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88
const dns = require('dns');
99

10+
if (!common.isMainThread)
11+
common.skip('Worker bootstrapping works differently -> different async IDs');
12+
1013
const hooks = initHooks();
1114

1215
hooks.enable();

test/async-hooks/test-getnameinforeqwrap.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88
const dns = require('dns');
99

10+
if (!common.isMainThread)
11+
common.skip('Worker bootstrapping works differently -> different async IDs');
12+
1013
const hooks = initHooks();
1114

1215
hooks.enable();

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
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-
}
6+
if (!common.isMainThread)
7+
common.skip('No signal handling available in Workers');
78

89
const initHooks = require('./init-hooks');
910
const verifyGraph = require('./verify-graph');

test/async-hooks/test-no-assert-when-disabled.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict';
22
// Flags: --no-force-async-hooks-checks --expose-internals
3-
require('../common');
3+
const common = require('../common');
4+
5+
if (!common.isMainThread)
6+
common.skip('Workers don\'t inherit per-env state like the check flag');
47

58
const async_hooks = require('internal/async_hooks');
69

test/async-hooks/test-pipewrap.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const initHooks = require('./init-hooks');
1010
const { checkInvocations } = require('./hook-checks');
1111
const spawn = require('child_process').spawn;
1212

13+
if (!common.isMainThread)
14+
common.skip('Worker bootstrapping works differently -> different async IDs');
15+
1316
const hooks = initHooks();
1417

1518
hooks.enable();

test/async-hooks/test-promise.chain-promise-before-init-hooks.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const common = require('../common');
44
const assert = require('assert');
55
const initHooks = require('./init-hooks');
66
const { checkInvocations } = require('./hook-checks');
7+
8+
if (!common.isMainThread)
9+
common.skip('Worker bootstrapping works differently -> different async IDs');
10+
711
common.crashOnUnhandledRejection();
812

913
const p = new Promise(common.mustCall(function executor(resolve, reject) {

test/async-hooks/test-promise.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const assert = require('assert');
66
const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88

9+
if (!common.isMainThread)
10+
common.skip('Worker bootstrapping works differently -> different async IDs');
11+
912
common.crashOnUnhandledRejection();
1013

1114
const hooks = initHooks();

test/async-hooks/test-signalwrap.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const common = require('../common');
33

44
if (common.isWindows)
55
common.skip('no signals in Windows');
6+
if (!common.isMainThread)
7+
common.skip('No signal handling available in Workers');
68

79
const assert = require('assert');
810
const initHooks = require('./init-hooks');

test/async-hooks/test-statwatcher.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const commonPath = require.resolve('../common');
55
const assert = require('assert');
66
const initHooks = require('./init-hooks');
77
const { checkInvocations } = require('./hook-checks');
88
const fs = require('fs');
99

10+
if (!common.isMainThread)
11+
common.skip('Worker bootstrapping works differently -> different async IDs');
12+
1013
const hooks = initHooks();
1114
hooks.enable();
1215

test/common/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ Object.defineProperty(exports, 'PORT', {
4646
enumerable: true
4747
});
4848

49+
exports.isMainThread = (() => {
50+
try {
51+
return require('worker').isMainThread;
52+
} catch {
53+
// Worker module not enabled → only a single main thread exists.
54+
return true;
55+
}
56+
})();
4957

5058
exports.isWindows = process.platform === 'win32';
5159
exports.isWOW64 = exports.isWindows &&
@@ -746,6 +754,10 @@ exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() {
746754
if (process.config.variables.v8_enable_inspector === 0) {
747755
exports.skip('V8 inspector is disabled');
748756
}
757+
if (!exports.isMainThread) {
758+
// TODO(addaleax): Fix me.
759+
exports.skip('V8 inspector is not available in Workers');
760+
}
749761
};
750762

751763
exports.skipIf32Bits = function skipIf32Bits() {

test/known_issues/test-stdin-is-always-net.socket.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ const proc = spawn(
1919
// To double-check this test, set stdio to 'pipe' and uncomment the line below.
2020
// proc.stderr.pipe(process.stderr);
2121
proc.on('exit', common.mustCall(function(exitCode) {
22-
process.exitCode = exitCode;
22+
assert.strictEqual(exitCode, 0);
2323
}));

test/parallel/test-async-hooks-disable-during-promise.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const common = require('../common');
33
const async_hooks = require('async_hooks');
44
common.crashOnUnhandledRejection();
55

6+
if (!common.isMainThread)
7+
common.skip('Worker bootstrapping works differently -> different AsyncWraps');
8+
69
const hook = async_hooks.createHook({
710
init: common.mustCall(2),
811
before: common.mustCall(1),

test/parallel/test-async-hooks-disable-gc-tracking.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const common = require('../common');
88
const async_hooks = require('async_hooks');
99

1010
const hook = async_hooks.createHook({
11-
destroy: common.mustCall(1) // only 1 immediate is destroyed
11+
destroy: common.mustCallAtLeast(1) // only 1 immediate is destroyed
1212
}).enable();
1313

1414
new async_hooks.AsyncResource('foobar', { requireManualDestroy: true });

test/parallel/test-async-hooks-enable-during-promise.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ common.crashOnUnhandledRejection();
77
Promise.resolve(1).then(common.mustCall(() => {
88
async_hooks.createHook({
99
init: common.mustCall(),
10-
before: common.mustCall(),
11-
after: common.mustCall(2)
10+
before: common.mustCallAtLeast(),
11+
after: common.mustCallAtLeast(2)
1212
}).enable();
1313

1414
process.nextTick(common.mustCall());

test/parallel/test-async-hooks-prevent-double-destroy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const common = require('../common');
88
const async_hooks = require('async_hooks');
99

1010
const hook = async_hooks.createHook({
11-
destroy: common.mustCall(2) // 1 immediate + manual destroy
11+
destroy: common.mustCallAtLeast(2) // 1 immediate + manual destroy
1212
}).enable();
1313

1414
{

test/parallel/test-async-hooks-promise-triggerid.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const common = require('../common');
33
const assert = require('assert');
44
const async_hooks = require('async_hooks');
55

6+
if (!common.isMainThread)
7+
common.skip('Worker bootstrapping works differently -> different async IDs');
8+
69
common.crashOnUnhandledRejection();
710

811
const promiseAsyncIds = [];

test/parallel/test-async-hooks-promise.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const common = require('../common');
33
const assert = require('assert');
44
const async_hooks = require('async_hooks');
55

6+
if (!common.isMainThread)
7+
common.skip('Worker bootstrapping works differently -> different async IDs');
8+
69
const initCalls = [];
710
const resolveCalls = [];
811

test/parallel/test-async-hooks-top-level-clearimmediate.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const common = require('../common');
66
const assert = require('assert');
77
const async_hooks = require('async_hooks');
88

9+
if (!common.isMainThread)
10+
common.skip('Worker bootstrapping works differently -> different async IDs');
11+
912
let seenId, seenResource;
1013

1114
async_hooks.createHook({

test/parallel/test-async-wrap-promise-after-enabled.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
const common = require('../common');
66
const assert = require('assert');
77

8+
if (!common.isMainThread)
9+
common.skip('Worker bootstrapping works differently -> different timing');
10+
811
const async_hooks = require('async_hooks');
912

1013
const seenEvents = [];

test/parallel/test-child-process-custom-fds.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const assert = require('assert');
55
const internalCp = require('internal/child_process');
66
const oldSpawnSync = internalCp.spawnSync;
77

8+
if (!common.isMainThread)
9+
common.skip('stdio is not associated with file descriptors in Workers');
10+
811
// Verify that customFds is used if stdio is not provided.
912
{
1013
const msg = 'child_process: options.customFds option is deprecated. ' +

test/parallel/test-child-process-http-socket-leak.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const common = require('../common');
66
const assert = require('assert');
77
const { fork } = require('child_process');
88
const http = require('http');
9-
const { kTimeout } = require('internal/timers');
109

1110
if (process.argv[2] === 'child') {
1211
process.once('message', (req, socket) => {
@@ -19,6 +18,8 @@ if (process.argv[2] === 'child') {
1918
return;
2019
}
2120

21+
const { kTimeout } = require('internal/timers');
22+
2223
let child;
2324
let socket;
2425

test/parallel/test-child-process-validate-stdio.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ common.expectsError(() => _validateStdio(stdio2, true),
3030
{ code: 'ERR_IPC_SYNC_FORK', type: Error }
3131
);
3232

33-
{
33+
34+
if (common.isMainThread) {
3435
const stdio3 = [process.stdin, process.stdout, process.stderr];
3536
const result = _validateStdio(stdio3, false);
3637
assert.deepStrictEqual(result, {
@@ -42,4 +43,7 @@ common.expectsError(() => _validateStdio(stdio2, true),
4243
ipc: undefined,
4344
ipcFd: undefined
4445
});
46+
} else {
47+
common.printSkipMessage(
48+
'stdio is not associated with file descriptors in Workers');
4549
}

test/parallel/test-cli-eval.js

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const path = require('path');
3434
const fixtures = require('../common/fixtures');
3535
const nodejs = `"${process.execPath}"`;
3636

37+
if (!common.isMainThread)
38+
common.skip('process.chdir is not available in Workers');
39+
3740
if (process.argv.length > 2) {
3841
console.log(process.argv.slice(2).join(' '));
3942
process.exit(0);

test/parallel/test-cli-node-options-disallowed.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const common = require('../common');
33
if (process.config.variables.node_without_node_options)
44
common.skip('missing NODE_OPTIONS support');
5+
if (!common.isMainThread)
6+
common.skip('process.chdir is not available in Workers');
57

68
// Test options specified by env variable.
79

test/parallel/test-cli-node-options.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const common = require('../common');
33
if (process.config.variables.node_without_node_options)
44
common.skip('missing NODE_OPTIONS support');
5+
if (!common.isMainThread)
6+
common.skip('process.chdir is not available in Workers');
57

68
// Test options specified by env variable.
79

test/parallel/test-cluster-net-listen-relative-path.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const tmpdir = require('../common/tmpdir');
1111
if (common.isWindows)
1212
common.skip('On Windows named pipes live in their own ' +
1313
'filesystem and don\'t have a ~100 byte limit');
14+
if (!common.isMainThread)
15+
common.skip('process.chdir is not available in Workers');
1416

1517
// Choose a socket name such that the absolute path would exceed 100 bytes.
1618
const socketDir = './unix-socket-dir';

test/parallel/test-console.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ const assert = require('assert');
2626
assert.ok(process.stdout.writable);
2727
assert.ok(process.stderr.writable);
2828
// Support legacy API
29-
assert.strictEqual(typeof process.stdout.fd, 'number');
30-
assert.strictEqual(typeof process.stderr.fd, 'number');
31-
29+
if (common.isMainThread) {
30+
assert.strictEqual(typeof process.stdout.fd, 'number');
31+
assert.strictEqual(typeof process.stderr.fd, 'number');
32+
}
3233
process.once('warning', common.mustCall((warning) => {
3334
assert(/no such label/.test(warning.message));
3435
}));

0 commit comments

Comments
 (0)