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: https://github.com/nodejs/node/pull/56712
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
James M Snell 2025-01-22 14:19:38 -08:00 committed by Node.js GitHub Bot
parent 0713ee3a17
commit 8caa1dcee6
148 changed files with 673 additions and 291 deletions

View File

@ -1,8 +1,47 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const cp = require('child_process');
function getPrintedStackTrace(stderr) {
const lines = stderr.split('\n');
let state = 'initial';
const result = {
message: [],
nativeStack: [],
jsStack: [],
};
for (let i = 0; i < lines.length; ++i) {
const line = lines[i].trim();
if (line.length === 0) {
continue; // Skip empty lines.
}
switch (state) {
case 'initial':
result.message.push(line);
if (line.includes('Native stack trace')) {
state = 'native-stack';
} else {
result.message.push(line);
}
break;
case 'native-stack':
if (line.includes('JavaScript stack trace')) {
state = 'js-stack';
} else {
result.nativeStack.push(line);
}
break;
case 'js-stack':
result.jsStack.push(line);
break;
}
}
return result;
}
if (process.argv[2] === 'child') {
process.abort();
} else {
@ -10,7 +49,7 @@ if (process.argv[2] === 'child') {
const stderr = child.stderr.toString();
assert.strictEqual(child.stdout.toString(), '');
const { nativeStack, jsStack } = common.getPrintedStackTrace(stderr);
const { nativeStack, jsStack } = getPrintedStackTrace(stderr);
if (!nativeStack.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
@ -18,7 +57,7 @@ if (process.argv[2] === 'child') {
// For systems that don't support backtraces, the native stack is
// going to be empty.
if (!common.isWindows && nativeStack.length > 0) {
if (process.platform !== 'win32' && nativeStack.length > 0) {
const { getBinaryPath } = require('../common/shared-lib-util');
if (!nativeStack.some((frame) => frame.includes(`[${getBinaryPath()}]`))) {
assert.fail(`Some native stack frame include the binary name:\n${stderr}`);

View File

@ -1,9 +1,10 @@
'use strict';
// Flags: --expose-gc
const common = require('../common');
require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const { isMainThread } = require('worker_threads');
const util = require('util');
const print = process._rawDebug;
@ -161,7 +162,7 @@ class ActivityCollector {
const stub = { uid, type: 'Unknown', handleIsObject: true, handle: {} };
this._activities.set(uid, stub);
return stub;
} else if (!common.isMainThread) {
} else if (!isMainThread) {
// Worker threads start main script execution inside of an AsyncWrap
// callback, so we don't yield errors for these.
return null;

View File

@ -1,10 +1,13 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
if (!common.hasCrypto) {
common.skip('missing crypto');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const assert = require('assert');
const tick = require('../common/tick');

View File

@ -1,10 +1,13 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
if (!common.hasCrypto) {
common.skip('missing crypto');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const assert = require('assert');
const tick = require('../common/tick');

View File

@ -87,8 +87,9 @@ const assert = require('assert');
const tick = require('../common/tick');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread)
common.skip('Worker bootstrapping works differently -> different timing');
// Include "Unknown"s because hook2 will not be able to identify

View File

@ -6,12 +6,15 @@ const initHooks = require('./init-hooks');
const tick = require('../common/tick');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
if (common.isIBMi)
if (common.isIBMi) {
common.skip('IBMi does not support fs.watch()');
}
const hooks = initHooks();

View File

@ -6,9 +6,11 @@ const tick = require('../common/tick');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const hooks = initHooks();

View File

@ -6,9 +6,11 @@ const tick = require('../common/tick');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const dns = require('dns');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const hooks = initHooks();

View File

@ -6,9 +6,11 @@ const tick = require('../common/tick');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const dns = require('dns');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const hooks = initHooks();

View File

@ -1,10 +1,13 @@
'use strict';
const common = require('../common');
if (common.isWindows)
if (common.isWindows) {
common.skip('no signals on Windows');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('No signal handling available in Workers');
}
const initHooks = require('./init-hooks');
const verifyGraph = require('./verify-graph');

View File

@ -1,9 +1,10 @@
'use strict';
// Flags: --no-force-async-hooks-checks --expose-internals
const common = require('../common');
if (!common.isMainThread)
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('Workers don\'t inherit per-env state like the check flag');
}
const async_hooks = require('internal/async_hooks');

View File

@ -9,9 +9,11 @@ const tick = require('../common/tick');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const { spawn } = require('child_process');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const hooks = initHooks();

View File

@ -4,9 +4,11 @@ const common = require('../common');
const assert = require('assert');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const p = new Promise(common.mustCall(function executor(resolve) {
resolve(5);

View File

@ -5,9 +5,11 @@ const common = require('../common');
const assert = require('assert');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const hooks = initHooks();

View File

@ -1,10 +1,13 @@
'use strict';
const common = require('../common');
if (common.isWindows)
if (common.isWindows) {
common.skip('no signals in Windows');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('No signal handling available in Workers');
}
const assert = require('assert');
const initHooks = require('./init-hooks');

View File

@ -7,8 +7,11 @@ const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');
if (!common.isMainThread)
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
tmpdir.refresh();

View File

@ -5,9 +5,11 @@ const common = require('../common');
const assert = require('assert');
const initHooks = require('./init-hooks');
const async_hooks = require('async_hooks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const promiseAsyncIds = [];
const hooks = initHooks({

View File

@ -6,7 +6,9 @@ if (common.isWindows) {
common.skip('vcbuild.bat doesn\'t build the n-api benchmarks yet');
}
if (!common.isMainThread) {
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('addons are not supported in workers');
}

View File

@ -102,10 +102,6 @@ symlinks
([SeCreateSymbolicLinkPrivilege](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530716\(v=vs.85\).aspx)).
On non-Windows platforms, this always returns `true`.
### `createZeroFilledFile(filename)`
Creates a 10 MiB file of all null characters.
### `enoughTestMem`
* [\<boolean>][<boolean>]
@ -257,10 +253,6 @@ Platform check for Advanced Interactive eXecutive (AIX).
Attempts to 'kill' `pid`
### `isDumbTerminal`
* [\<boolean>][<boolean>]
### `isFreeBSD`
* [\<boolean>][<boolean>]
@ -456,10 +448,6 @@ will not be run.
Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`.
### `skipIfDumbTerminal()`
Skip the rest of the tests if the current terminal is a dumb terminal
### `skipIfEslintMissing()`
Skip the rest of the tests in the current file when `ESLint` is not available
@ -475,11 +463,6 @@ was disabled at compile time.
Skip the rest of the tests in the current file when the Node.js executable
was compiled with a pointer size smaller than 64 bits.
### `skipIfWorker()`
Skip the rest of the tests in the current file when not running on a main
thread.
## ArrayStream module
The `ArrayStream` module provides a simple `Stream` that pushes elements from

View File

@ -139,8 +139,6 @@ const isPi = (() => {
}
})();
const isDumbTerminal = process.env.TERM === 'dumb';
// When using high concurrency or in the CI we need much more time for each connection attempt
net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(net.getDefaultAutoSelectFamilyAttemptTimeout() * 10));
const defaultAutoSelectFamilyAttemptTimeout = net.getDefaultAutoSelectFamilyAttemptTimeout();
@ -243,13 +241,6 @@ function childShouldThrowAndAbort() {
});
}
function createZeroFilledFile(filename) {
const fd = fs.openSync(filename, 'w');
fs.ftruncateSync(fd, 10 * 1024 * 1024);
fs.closeSync(fd);
}
const pwdCommand = isWindows ?
['cmd.exe', ['/d', '/c', 'cd']] :
['pwd', []];
@ -716,12 +707,6 @@ function skipIf32Bits() {
}
}
function skipIfWorker() {
if (!isMainThread) {
skip('This test only works on a main thread');
}
}
function getArrayBufferViews(buf) {
const { buffer, byteOffset, byteLength } = buf;
@ -806,12 +791,6 @@ function invalidArgTypeHelper(input) {
return ` Received type ${typeof input} (${inspected})`;
}
function skipIfDumbTerminal() {
if (isDumbTerminal) {
skip('skipping - dumb terminal');
}
}
function requireNoPackageJSONAbove(dir = __dirname) {
let possiblePackage = path.join(dir, '..', 'package.json');
let lastPackage = null;
@ -882,45 +861,6 @@ function escapePOSIXShell(cmdParts, ...args) {
return [cmd, { env }];
};
function getPrintedStackTrace(stderr) {
const lines = stderr.split('\n');
let state = 'initial';
const result = {
message: [],
nativeStack: [],
jsStack: [],
};
for (let i = 0; i < lines.length; ++i) {
const line = lines[i].trim();
if (line.length === 0) {
continue; // Skip empty lines.
}
switch (state) {
case 'initial':
result.message.push(line);
if (line.includes('Native stack trace')) {
state = 'native-stack';
} else {
result.message.push(line);
}
break;
case 'native-stack':
if (line.includes('JavaScript stack trace')) {
state = 'js-stack';
} else {
result.nativeStack.push(line);
}
break;
case 'js-stack':
result.jsStack.push(line);
break;
}
}
return result;
}
/**
* Check the exports of require(esm).
* TODO(joyeecheung): use it in all the test-require-module-* tests to minimize changes
@ -943,7 +883,6 @@ const common = {
buildType,
canCreateSymLink,
childShouldThrowAndAbort,
createZeroFilledFile,
defaultAutoSelectFamilyAttemptTimeout,
escapePOSIXShell,
expectsError,
@ -951,7 +890,6 @@ const common = {
expectWarning,
getArrayBufferViews,
getBufferSources,
getPrintedStackTrace,
getTTYfd,
hasIntl,
hasCrypto,
@ -960,10 +898,8 @@ const common = {
isAlive,
isASan,
isDebug,
isDumbTerminal,
isFreeBSD,
isLinux,
isMainThread,
isOpenBSD,
isMacOS,
isPi,
@ -985,10 +921,8 @@ const common = {
runWithInvalidFD,
skip,
skipIf32Bits,
skipIfDumbTerminal,
skipIfEslintMissing,
skipIfInspectorDisabled,
skipIfWorker,
spawnPromisified,
get enoughTestMem() {

View File

@ -8,7 +8,6 @@ const {
buildType,
canCreateSymLink,
childShouldThrowAndAbort,
createZeroFilledFile,
enoughTestMem,
escapePOSIXShell,
expectsError,
@ -21,12 +20,10 @@ const {
hasIPv6,
isAIX,
isAlive,
isDumbTerminal,
isFreeBSD,
isIBMi,
isInsideDirWithUnusualChars,
isLinux,
isMainThread,
isOpenBSD,
isMacOS,
isSunOS,
@ -45,7 +42,6 @@ const {
runWithInvalidFD,
skip,
skipIf32Bits,
skipIfDumbTerminal,
skipIfEslintMissing,
skipIfInspectorDisabled,
spawnPromisified,
@ -59,7 +55,6 @@ export {
canCreateSymLink,
childShouldThrowAndAbort,
createRequire,
createZeroFilledFile,
enoughTestMem,
escapePOSIXShell,
expectsError,
@ -73,12 +68,10 @@ export {
hasIPv6,
isAIX,
isAlive,
isDumbTerminal,
isFreeBSD,
isIBMi,
isInsideDirWithUnusualChars,
isLinux,
isMainThread,
isOpenBSD,
isMacOS,
isSunOS,
@ -97,7 +90,6 @@ export {
runWithInvalidFD,
skip,
skipIf32Bits,
skipIfDumbTerminal,
skipIfEslintMissing,
skipIfInspectorDisabled,
spawnPromisified,

View File

@ -13,8 +13,10 @@ import path from 'path';
import fs from 'fs';
import url from 'url';
import process from 'process';
import { isMainThread } from 'worker_threads';
if (!common.isMainThread) {
if (!isMainThread) {
common.skip(
'test-esm-resolve-type.mjs: process.chdir is not available in Workers'
);

View File

@ -3,7 +3,11 @@
const common = require('../common');
// Can't process.chdir() in worker.
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');

View File

@ -1,7 +1,11 @@
'use strict';
const common = require('../../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const fs = require('fs');
@ -553,4 +557,4 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
}, {
code: 'ERR_ACCESS_DENIED',
});
}
}

View File

@ -1,5 +1,9 @@
const common = require('../../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');

View File

@ -5,9 +5,11 @@ const cp = require('child_process');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
const util = require('util');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const traceFile = 'node_trace.1.log';

View File

@ -1,9 +1,11 @@
'use strict';
const common = require('../common');
const async_hooks = require('async_hooks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different AsyncWraps');
}
const hook = async_hooks.createHook({
init: common.mustCall(2),

View File

@ -2,9 +2,11 @@
const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const promiseAsyncIds = [];

View File

@ -2,9 +2,11 @@
const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
const initCalls = [];
const resolveCalls = [];

View File

@ -5,9 +5,11 @@
const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different async IDs');
}
let seenId, seenResource;

View File

@ -4,9 +4,11 @@
const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different timing');
}
const async_hooks = require('async_hooks');

View File

@ -115,7 +115,9 @@ expected.atRunTime = new Set([
'NativeModule internal/modules/esm/utils',
]);
if (common.isMainThread) {
const { isMainThread } = require('worker_threads');
if (isMainThread) {
[
'NativeModule url',
].forEach(expected.beforePreExec.add.bind(expected.beforePreExec));
@ -186,7 +188,7 @@ function err(message) {
}
}
if (common.isMainThread) {
if (isMainThread) {
const missing = expected.beforePreExec.difference(actual.beforePreExec);
const extra = actual.beforePreExec.difference(expected.beforePreExec);
if (missing.size !== 0) {
@ -212,10 +214,10 @@ if (common.isMainThread) {
}
}
if (!common.isMainThread) {
if (!isMainThread) {
// For workers, just merge beforePreExec into atRunTime for now.
// When we start adding modules to the worker snapshot, this branch
// can be removed and we can just remove the common.isMainThread
// can be removed and we can just remove the isMainThread
// conditions.
expected.beforePreExec.forEach(expected.atRunTime.add.bind(expected.atRunTime));
actual.beforePreExec.forEach(actual.atRunTime.add.bind(actual.atRunTime));

View File

@ -43,7 +43,9 @@ assert.throws(() => getValidStdio(stdio2, true),
assert.throws(() => getValidStdio(stdio), expectedError);
}
if (common.isMainThread) {
const { isMainThread } = require('worker_threads');
if (isMainThread) {
const stdio3 = [process.stdin, process.stdout, process.stderr];
const result = getValidStdio(stdio3, false);
assert.deepStrictEqual(result, {

View File

@ -1,11 +1,16 @@
'use strict';
const common = require('../common');
if (common.isWindows)
if (common.isWindows) {
common.skip('On Windows named pipes live in their own ' +
'filesystem and don\'t have a ~100 byte limit');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const assert = require('assert');
const cluster = require('cluster');

View File

@ -5,7 +5,8 @@
// and the cache is used when built in modules are compiled.
// Otherwise, verifies that no cache is used when compiling builtins.
const { isMainThread } = require('../common');
require('../common');
const { isMainThread } = require('worker_threads');
const assert = require('assert');
const {
internalBinding

View File

@ -1,6 +1,6 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const stdoutWrite = process.stdout.write;
@ -18,7 +18,7 @@ function doTest(isTTY, check) {
}
// Fake TTY
if (!common.isDumbTerminal) {
if (process.env.TERM !== 'dumb') {
doTest(true, check);
}
doTest(false, '');

View File

@ -31,10 +31,12 @@ const {
restoreStderr
} = require('../common/hijackstdio');
const { isMainThread } = require('worker_threads');
assert.ok(process.stdout.writable);
assert.ok(process.stderr.writable);
// Support legacy API
if (common.isMainThread) {
if (isMainThread) {
assert.strictEqual(typeof process.stdout.fd, 'number');
assert.strictEqual(typeof process.stderr.fd, 'number');
}

View File

@ -11,8 +11,9 @@ if (!hasOpenSSL3)
const assert = require('node:assert/strict');
const crypto = require('node:crypto');
const { isMainThread } = require('worker_threads');
if (common.isMainThread) {
if (isMainThread) {
// TODO(richardlau): Decide if `crypto.setFips` should error if the
// provider named "fips" is not available.
crypto.setFips(1);

View File

@ -1,10 +1,15 @@
'use strict';
const common = require('../common');
// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi)
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi) {
common.skip('cannot rmdir current working directory');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const assert = require('assert');
const fs = require('fs');

View File

@ -1,10 +1,15 @@
'use strict';
const common = require('../common');
// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi)
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi) {
common.skip('cannot rmdir current working directory');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const assert = require('assert');
const fs = require('fs');

View File

@ -1,10 +1,15 @@
'use strict';
const common = require('../common');
// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi)
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi) {
common.skip('cannot rmdir current working directory');
if (!common.isMainThread)
}
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const assert = require('assert');
const fs = require('fs');

View File

@ -24,6 +24,7 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { isMainThread } = require('worker_threads');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
@ -217,7 +218,7 @@ function nextdir() {
// mkdirpSync dirname loop
// XXX: windows and smartos have issues removing a directory that you're in.
if (common.isMainThread && (common.isLinux || common.isMacOS)) {
if (isMainThread && (common.isLinux || common.isMacOS)) {
const pathname = tmpdir.resolve(nextdir());
fs.mkdirSync(pathname);
process.chdir(pathname);

View File

@ -23,9 +23,11 @@
const common = require('../common');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const assert = require('assert');
const fs = require('fs');

View File

@ -5,6 +5,8 @@ const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const { isMainThread } = require('worker_threads');
tmpdir.refresh();
const url = fixtures.fileURL('a.js');
@ -86,7 +88,7 @@ if (common.isWindows) {
// Test that strings are interpreted as paths and not as URL
// Can't use process.chdir in Workers
// Please avoid testing fs.rmdir('file:') or using it as cleanup
if (common.isMainThread && !common.isWindows) {
if (isMainThread && !common.isWindows) {
const oldCwd = process.cwd();
process.chdir(tmpdir.path);

View File

@ -21,9 +21,11 @@
'use strict';
const common = require('../common');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('Setting process.umask is not supported in Workers');
}
const assert = require('assert');
const fs = require('fs');

View File

@ -1,9 +1,12 @@
'use strict';
// http://groups.google.com/group/nodejs/browse_thread/thread/f66cd3c960406919
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasCrypto) {
common.skip('missing crypto');
}
const fs = require('fs');
const assert = require('assert');
if (process.argv[2] === 'request') {
@ -73,7 +76,11 @@ function executeRequest(cb) {
tmpdir.refresh();
common.createZeroFilledFile(filename);
// Create a zero-filled file.
const fd = fs.openSync(filename, 'w');
fs.ftruncateSync(fd, 10 * 1024 * 1024);
fs.closeSync(fd);
server = http.createServer(function(req, res) {
res.writeHead(200);

View File

@ -4,7 +4,7 @@ const assert = require('assert');
const { execFileSync } = require('child_process');
const { readFileSync, globSync } = require('fs');
const { path } = require('../common/fixtures');
const { isMainThread } = require('worker_threads');
// This test checks for regressions in environment variable handling and
// caching, but the localization data originated from ICU might change
@ -169,7 +169,7 @@ if (isMockable) {
// Tests with process.env mutated inside
{
// process.env.TZ is not intercepted in Workers
if (common.isMainThread) {
if (isMainThread) {
assert.strictEqual(
isSet(zones.map((TZ) => runEnvInside({ TZ }, () => new Date(333333333333).toString()))),
true

View File

@ -3,7 +3,12 @@
const common = require('../common');
common.skipIfInspectorDisabled();
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const inspector = require('inspector');

View File

@ -3,7 +3,12 @@
const common = require('../common');
common.skipIfInspectorDisabled();
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const { Worker } = require('worker_threads');

View File

@ -6,7 +6,11 @@ common.skipIf32Bits();
const { NodeInstance } = require('../common/inspector-helper.js');
const assert = require('assert');
common.skipIfWorker(); // Signal starts a server for a main thread inspector
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const script = `
process._rawDebug('Waiting until a signal enables the inspector...');

View File

@ -10,8 +10,8 @@ const { pathToFileURL } = require('url');
const { isMainThread, parentPort, Worker, workerData } =
require('worker_threads');
if (!workerData) {
common.skipIfWorker();
if (!workerData && !isMainThread) {
common.skip('This test only works on a main thread');
}
function toDebug() {

View File

@ -6,8 +6,8 @@ common.skipIfInspectorDisabled();
const { Session } = require('inspector');
const { Worker, isMainThread, workerData } = require('worker_threads');
if (!workerData) {
common.skipIfWorker();
if (!workerData && !isMainThread) {
common.skip('This test only works on a main thread');
}
if (isMainThread) {

View File

@ -9,6 +9,8 @@ const assert = require('assert');
const vm = require('vm');
const { Session } = require('inspector');
const { gcUntil } = require('../common/gc');
const { isMainThread } = require('worker_threads');
const session = new Session();
session.connect();
@ -34,7 +36,7 @@ async function testContextCreatedAndDestroyed() {
assert.strictEqual(name.includes(`[${process.pid}]`), true);
} else {
let expects = `${process.argv0}[${process.pid}]`;
if (!common.isMainThread) {
if (!isMainThread) {
expects = `Worker[${require('worker_threads').threadId}]`;
}
assert.strictEqual(expects, name);

View File

@ -3,9 +3,15 @@
const common = require('../common');
common.skipIfInspectorDisabled();
const { parentPort, workerData, Worker } = require('node:worker_threads');
if (!workerData) {
common.skipIfWorker();
const {
isMainThread,
parentPort,
workerData,
Worker,
} = require('node:worker_threads');
if (!workerData && !isMainThread) {
common.skip('This test only works on a main thread');
}
const inspector = require('node:inspector');

View File

@ -3,9 +3,9 @@
const common = require('../common');
common.skipIfInspectorDisabled();
const { workerData, Worker } = require('node:worker_threads');
if (!workerData) {
common.skipIfWorker();
const { isMainThread, workerData, Worker } = require('node:worker_threads');
if (!workerData && !isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('node:assert');

View File

@ -7,7 +7,12 @@ const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
common.skipIfInspectorDisabled();
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
tmpdir.refresh();

View File

@ -5,7 +5,12 @@
const common = require('../common');
common.skipIfInspectorDisabled();
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const inspector = require('inspector');

View File

@ -13,9 +13,11 @@
const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('--require does not work with Workers');
}
const inspector = require('inspector');
const msg = 'Test inspector logging';

View File

@ -3,7 +3,12 @@
const common = require('../common');
common.skipIfInspectorDisabled();
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
// Assert that even when started with `--inspect=0` workers are assigned
// consecutive (i.e. deterministically predictable) debug ports

View File

@ -3,7 +3,13 @@
const common = require('../common');
common.skipIfInspectorDisabled();
common.skipIfWorker(); // https://github.com/nodejs/node/issues/22767
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
// https://github.com/nodejs/node/issues/22767
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const { Session } = require('inspector');

View File

@ -6,8 +6,8 @@ common.skipIfInspectorDisabled();
const { Worker, isMainThread, parentPort, workerData } =
require('worker_threads');
if (isMainThread || workerData !== 'launched by test') {
common.skipIfWorker();
if (!isMainThread || workerData !== 'launched by test') {
common.skip('This test only works on a main thread');
}
const { Session } = require('inspector');

View File

@ -8,8 +8,9 @@
// 3. Deprecated modules are properly deprecated.
const common = require('../common');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread) {
if (!isMainThread) {
common.skip('Cannot test the existence of --expose-internals from worker');
}

View File

@ -1,7 +1,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const { spawnSync } = require('node:child_process');
const assert = require('node:assert');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const { createRequire } = require('node:module');
const assert = require('node:assert');

View File

@ -2,7 +2,13 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const childProcess = require('child_process');
const fs = require('fs');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const { WASI } = require('wasi');

View File

@ -2,7 +2,12 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const childProcess = require('child_process');

View File

@ -3,7 +3,11 @@
const common = require('../common');
const path = require('path');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const { spawnSync } = require('child_process');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
if (!common.hasCrypto) {
common.skip('no crypto');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
if (!common.hasCrypto) {
common.skip('no crypto');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const { spawnSync } = require('child_process');

View File

@ -3,7 +3,11 @@
const common = require('../common');
const path = require('path');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const { spawnSync } = require('child_process');

View File

@ -2,7 +2,13 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const fixtures = require('../common/fixtures');
const assert = require('node:assert');

View File

@ -2,7 +2,12 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const path = require('path');

View File

@ -2,11 +2,19 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
if (!common.canCreateSymLink())
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
if (!common.canCreateSymLink()) {
common.skip('insufficient privileges');
if (!common.hasCrypto)
}
if (!common.hasCrypto) {
common.skip('no crypto');
}
const assert = require('assert');
const fs = require('fs');
@ -15,9 +23,7 @@ const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { spawnSync } = require('child_process');
{
tmpdir.refresh();
}
tmpdir.refresh();
const readOnlyFolder = tmpdir.resolve('read-only');
const readWriteFolder = tmpdir.resolve('read-write');

View File

@ -2,13 +2,19 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const fixtures = require('../common/fixtures');
if (!common.canCreateSymLink())
if (!common.canCreateSymLink()) {
common.skip('insufficient privileges');
if (!common.hasCrypto)
}
if (!common.hasCrypto) {
common.skip('no crypto');
}
const assert = require('assert');
const fs = require('fs');

View File

@ -2,13 +2,20 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const fixtures = require('../common/fixtures');
if (!common.canCreateSymLink())
if (!common.canCreateSymLink()) {
common.skip('insufficient privileges');
if (!common.hasCrypto)
}
if (!common.hasCrypto) {
common.skip('no crypto');
}
const assert = require('assert');
const fs = require('fs');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const path = require('path');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
const { spawnSync } = require('child_process');

View File

@ -2,9 +2,15 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
if (!common.hasCrypto)
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
if (!common.hasCrypto) {
common.skip('no crypto');
}
const assert = require('assert');

View File

@ -2,9 +2,15 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
if (!common.hasCrypto)
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
if (!common.hasCrypto) {
common.skip('no crypto');
}
const assert = require('assert');
const v8 = require('v8');

View File

@ -2,9 +2,15 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
if (!common.hasCrypto)
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
if (!common.hasCrypto) {
common.skip('no crypto');
}
const assert = require('assert');
const path = require('path');

View File

@ -5,8 +5,12 @@ const assert = require('assert');
const { spawnSync } = require('child_process');
const fixtures = require('../common/fixtures');
const file = fixtures.path('permission', 'inspector-brk.js');
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
common.skipIfWorker();
common.skipIfInspectorDisabled();
// See https://github.com/nodejs/node/issues/53385

View File

@ -2,7 +2,12 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
common.skipIfInspectorDisabled();
const { Session } = require('inspector');

View File

@ -2,7 +2,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const { createRequire } = require('node:module');
const assert = require('node:assert');

View File

@ -1,7 +1,11 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
if (!common.hasCrypto) {
common.skip('no crypto');

View File

@ -2,13 +2,17 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const assert = require('assert');
const {
Worker,
isMainThread,
} = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
const assert = require('assert');
// Guarantee the initial state
{
assert.ok(!process.permission.has('worker'));

View File

@ -54,7 +54,12 @@ const server = http.createServer((req, res) => {
server.listen(0);
server.on('listening', () => {
common.createZeroFilledFile(filename);
// Create a zero-filled file
const fd = fs.openSync(filename, 'w');
fs.ftruncateSync(fd, 10 * 1024 * 1024);
fs.closeSync(fd);
makeRequest();
});

View File

@ -4,11 +4,13 @@ const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { exec } = require('child_process');
const { isMainThread } = require('worker_threads');
const nodeBinary = process.argv[0];
if (!common.isMainThread)
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const selfRefModule = fixtures.path('self_ref_module');
const fixtureA = fixtures.path('printA.js');

View File

@ -2,9 +2,11 @@
const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('process.abort() is not available in Workers');
}
// Check that our built-in methods do not have a prototype/constructor behaviour
// if they don't need to. This could be tested for any of our C++ methods.

View File

@ -1,6 +1,10 @@
'use strict';
const common = require('../common');
common.skipIfWorker();
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('This test only works on a main thread');
}
// Test that 'exit' is emitted if 'beforeExit' throws.

View File

@ -1,8 +1,11 @@
'use strict';
const common = require('../common');
if (!common.isMainThread)
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const assert = require('assert');
assert.throws(

View File

@ -4,9 +4,11 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('process.chdir is not available in Workers');
}
const tmpdir = require('../common/tmpdir');

View File

@ -1,12 +1,15 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('process.env.TZ is not intercepted in Workers');
}
if (common.isWindows) // Using a different TZ format.
if (common.isWindows) { // Using a different TZ format.
common.skip('todo: test on Windows');
}
const date = new Date('2018-04-14T12:34:56.789Z');

View File

@ -3,6 +3,8 @@
const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (common.isWindows) {
assert.strictEqual(process.geteuid, undefined);
assert.strictEqual(process.getegid, undefined);
@ -11,8 +13,9 @@ if (common.isWindows) {
return;
}
if (!common.isMainThread)
if (!isMainThread) {
return;
}
assert.throws(() => {
process.seteuid({});

View File

@ -1,8 +1,10 @@
'use strict';
const common = require('../common');
const { isMainThread } = require('worker_threads');
if (!common.isMainThread)
if (!isMainThread) {
common.skip('execArgv does not affect Workers');
}
// This test ensures that no asynchronous operations are performed in the 'exit'
// handler.

View File

@ -1,6 +1,7 @@
import { isMainThread, hasCrypto, hasIntl } from '../common/index.mjs';
import { hasCrypto, hasIntl } from '../common/index.mjs';
import assert from 'node:assert';
import { builtinModules } from 'node:module';
import { isMainThread } from 'node:worker_threads';
for (const invalid of [1, undefined, null, false, [], {}, () => {}, Symbol('test')]) {
assert.throws(() => process.getBuiltinModule(invalid), { code: 'ERR_INVALID_ARG_TYPE' });

View File

@ -7,8 +7,11 @@ if (common.isWindows) {
return;
}
if (!common.isMainThread)
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
return;
}
[undefined, null, true, {}, [], () => {}].forEach((val) => {
assert.throws(

View File

@ -5,6 +5,7 @@ const fixtures = require('../../test/common/fixtures');
const assert = require('node:assert');
const { describe, it } = require('node:test');
const { join } = require('node:path');
const { isMainThread } = require('worker_threads');
const basicValidEnvFilePath = fixtures.path('dotenv/basic-valid.env');
const validEnvFilePath = fixtures.path('dotenv/valid.env');
@ -58,7 +59,7 @@ describe('process.loadEnvFile()', () => {
const originalCwd = process.cwd();
try {
if (common.isMainThread) {
if (isMainThread) {
process.chdir(join(originalCwd, 'lib'));
}
@ -66,7 +67,7 @@ describe('process.loadEnvFile()', () => {
process.loadEnvFile();
}, { code: 'ENOENT', syscall: 'open', path: '.env' });
} finally {
if (common.isMainThread) {
if (isMainThread) {
process.chdir(originalCwd);
}
}

View File

@ -1,14 +1,16 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (common.isWindows) {
assert.strictEqual(process.setgroups, undefined);
return;
}
if (!common.isMainThread)
if (!isMainThread) {
return;
}
assert.throws(
() => {

Some files were not shown because too many files have changed in this diff Show More