Skip to content

Commit

Permalink
test,tools: enable running tests under workers
Browse files Browse the repository at this point in the history
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 <gpunathi@in.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
addaleax authored and targos committed Jun 13, 2018
1 parent 9ad42b7 commit ed05d9a
Show file tree
Hide file tree
Showing 84 changed files with 274 additions and 37 deletions.
6 changes: 5 additions & 1 deletion test/async-hooks/init-hooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
// Flags: --expose-gc

require('../common');
const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const util = require('util');
Expand Down Expand Up @@ -162,6 +162,10 @@ class ActivityCollector {
const stub = { uid, type: 'Unknown', handleIsObject: true };
this._activities.set(uid, stub);
return stub;
} else if (!common.isMainThread) {
// Worker threads start main script execution inside of an AsyncWrap
// callback, so we don't yield errors for these.
return null;
} else {
const err = new Error(`Found a handle whose ${hook}` +
' hook was invoked but not its init hook');
Expand Down
2 changes: 2 additions & 0 deletions test/async-hooks/test-crypto-pbkdf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const assert = require('assert');
const tick = require('./tick');
Expand Down
2 changes: 2 additions & 0 deletions test/async-hooks/test-crypto-randomBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const assert = require('assert');
const tick = require('./tick');
Expand Down
3 changes: 3 additions & 0 deletions test/async-hooks/test-emit-before-after.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const spawnSync = require('child_process').spawnSync;
const async_hooks = require('internal/async_hooks');
const initHooks = require('./init-hooks');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

switch (process.argv[2]) {
case 'test_invalid_async_id':
async_hooks.emitBefore(-2, 1);
Expand Down
4 changes: 4 additions & 0 deletions test/async-hooks/test-enable-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const assert = require('assert');
const tick = require('./tick');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different timing');

// Include "Unknown"s because hook2 will not be able to identify
// the type of the first Immediate since it will miss its `init` invocation.
const types = [ 'Immediate', 'Unknown' ];
Expand Down
5 changes: 4 additions & 1 deletion test/async-hooks/test-fseventwrap.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
'use strict';
require('../common');
const common = require('../common');

const assert = require('assert');
const initHooks = require('./init-hooks');
const tick = require('./tick');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const hooks = initHooks();

hooks.enable();
Expand Down
3 changes: 3 additions & 0 deletions test/async-hooks/test-fsreqwrap-readFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const hooks = initHooks();

hooks.enable();
Expand Down
3 changes: 3 additions & 0 deletions test/async-hooks/test-getaddrinforeqwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const dns = require('dns');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const hooks = initHooks();

hooks.enable();
Expand Down
3 changes: 3 additions & 0 deletions test/async-hooks/test-getnameinforeqwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const dns = require('dns');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const hooks = initHooks();

hooks.enable();
Expand Down
5 changes: 3 additions & 2 deletions test/async-hooks/test-graph.signal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const common = require('../common');
if (common.isWindows) {
if (common.isWindows)
common.skip('no signals on Windows');
}
if (!common.isMainThread)
common.skip('No signal handling available in Workers');

const initHooks = require('./init-hooks');
const verifyGraph = require('./verify-graph');
Expand Down
5 changes: 4 additions & 1 deletion test/async-hooks/test-no-assert-when-disabled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';
// Flags: --no-force-async-hooks-checks --expose-internals
require('../common');
const common = require('../common');

if (!common.isMainThread)
common.skip('Workers don\'t inherit per-env state like the check flag');

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

Expand Down
3 changes: 3 additions & 0 deletions test/async-hooks/test-pipewrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const spawn = require('child_process').spawn;

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const hooks = initHooks();

hooks.enable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const common = require('../common');
const assert = require('assert');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

common.crashOnUnhandledRejection();

const p = new Promise(common.mustCall(function executor(resolve, reject) {
Expand Down
3 changes: 3 additions & 0 deletions test/async-hooks/test-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const assert = require('assert');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

common.crashOnUnhandledRejection();

const hooks = initHooks();
Expand Down
2 changes: 2 additions & 0 deletions test/async-hooks/test-signalwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const common = require('../common');

if (common.isWindows)
common.skip('no signals in Windows');
if (!common.isMainThread)
common.skip('No signal handling available in Workers');

const assert = require('assert');
const initHooks = require('./init-hooks');
Expand Down
5 changes: 4 additions & 1 deletion test/async-hooks/test-statwatcher.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
'use strict';

require('../common');
const common = require('../common');
const commonPath = require.resolve('../common');
const assert = require('assert');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const hooks = initHooks();
hooks.enable();

Expand Down
12 changes: 12 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Object.defineProperty(exports, 'PORT', {
enumerable: true
});

exports.isMainThread = (() => {
try {
return require('worker').isMainThread;
} catch {
// Worker module not enabled → only a single main thread exists.
return true;
}
})();

exports.isWindows = process.platform === 'win32';
exports.isWOW64 = exports.isWindows &&
Expand Down Expand Up @@ -746,6 +754,10 @@ exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() {
if (process.config.variables.v8_enable_inspector === 0) {
exports.skip('V8 inspector is disabled');
}
if (!exports.isMainThread) {
// TODO(addaleax): Fix me.
exports.skip('V8 inspector is not available in Workers');
}
};

exports.skipIf32Bits = function skipIf32Bits() {
Expand Down
2 changes: 1 addition & 1 deletion test/known_issues/test-stdin-is-always-net.socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ const proc = spawn(
// To double-check this test, set stdio to 'pipe' and uncomment the line below.
// proc.stderr.pipe(process.stderr);
proc.on('exit', common.mustCall(function(exitCode) {
process.exitCode = exitCode;
assert.strictEqual(exitCode, 0);
}));
3 changes: 3 additions & 0 deletions test/parallel/test-async-hooks-disable-during-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const common = require('../common');
const async_hooks = require('async_hooks');
common.crashOnUnhandledRejection();

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different AsyncWraps');

const hook = async_hooks.createHook({
init: common.mustCall(2),
before: common.mustCall(1),
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-async-hooks-disable-gc-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const common = require('../common');
const async_hooks = require('async_hooks');

const hook = async_hooks.createHook({
destroy: common.mustCall(1) // only 1 immediate is destroyed
destroy: common.mustCallAtLeast(1) // only 1 immediate is destroyed
}).enable();

new async_hooks.AsyncResource('foobar', { requireManualDestroy: true });
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-async-hooks-enable-during-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ common.crashOnUnhandledRejection();
Promise.resolve(1).then(common.mustCall(() => {
async_hooks.createHook({
init: common.mustCall(),
before: common.mustCall(),
after: common.mustCall(2)
before: common.mustCallAtLeast(),
after: common.mustCallAtLeast(2)
}).enable();

process.nextTick(common.mustCall());
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-async-hooks-prevent-double-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const common = require('../common');
const async_hooks = require('async_hooks');

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

{
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-async-hooks-promise-triggerid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

common.crashOnUnhandledRejection();

const promiseAsyncIds = [];
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-async-hooks-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

const initCalls = [];
const resolveCalls = [];

Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-async-hooks-top-level-clearimmediate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

let seenId, seenResource;

async_hooks.createHook({
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-async-wrap-promise-after-enabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
const common = require('../common');
const assert = require('assert');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different timing');

const async_hooks = require('async_hooks');

const seenEvents = [];
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-child-process-custom-fds.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const assert = require('assert');
const internalCp = require('internal/child_process');
const oldSpawnSync = internalCp.spawnSync;

if (!common.isMainThread)
common.skip('stdio is not associated with file descriptors in Workers');

// Verify that customFds is used if stdio is not provided.
{
const msg = 'child_process: options.customFds option is deprecated. ' +
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-child-process-http-socket-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const common = require('../common');
const assert = require('assert');
const { fork } = require('child_process');
const http = require('http');
const { kTimeout } = require('internal/timers');

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

const { kTimeout } = require('internal/timers');

let child;
let socket;

Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-child-process-validate-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ common.expectsError(() => _validateStdio(stdio2, true),
{ code: 'ERR_IPC_SYNC_FORK', type: Error }
);

{

if (common.isMainThread) {
const stdio3 = [process.stdin, process.stdout, process.stderr];
const result = _validateStdio(stdio3, false);
assert.deepStrictEqual(result, {
Expand All @@ -42,4 +43,7 @@ common.expectsError(() => _validateStdio(stdio2, true),
ipc: undefined,
ipcFd: undefined
});
} else {
common.printSkipMessage(
'stdio is not associated with file descriptors in Workers');
}
3 changes: 3 additions & 0 deletions test/parallel/test-cli-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const path = require('path');
const fixtures = require('../common/fixtures');
const nodejs = `"${process.execPath}"`;

if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');

if (process.argv.length > 2) {
console.log(process.argv.slice(2).join(' '));
process.exit(0);
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-cli-node-options-disallowed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
const common = require('../common');
if (process.config.variables.node_without_node_options)
common.skip('missing NODE_OPTIONS support');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');

// Test options specified by env variable.

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-cli-node-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
const common = require('../common');
if (process.config.variables.node_without_node_options)
common.skip('missing NODE_OPTIONS support');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');

// Test options specified by env variable.

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-cluster-net-listen-relative-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const tmpdir = require('../common/tmpdir');
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)
common.skip('process.chdir is not available in Workers');

// Choose a socket name such that the absolute path would exceed 100 bytes.
const socketDir = './unix-socket-dir';
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ const assert = require('assert');
assert.ok(process.stdout.writable);
assert.ok(process.stderr.writable);
// Support legacy API
assert.strictEqual(typeof process.stdout.fd, 'number');
assert.strictEqual(typeof process.stderr.fd, 'number');

if (common.isMainThread) {
assert.strictEqual(typeof process.stdout.fd, 'number');
assert.strictEqual(typeof process.stderr.fd, 'number');
}
process.once('warning', common.mustCall((warning) => {
assert(/no such label/.test(warning.message));
}));
Expand Down
Loading

0 comments on commit ed05d9a

Please sign in to comment.