★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/ed05d9a821Nouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files

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 <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 May 17, 2018
1 parent 9ad42b7 commit ed05d9a8216866166538d239e1cd39fffc18d5b8
Showing with 274 additions and 37 deletions.
  1. +5 −1 test/async-hooks/init-hooks.js
  2. +2 −0 test/async-hooks/test-crypto-pbkdf2.js
  3. +2 −0 test/async-hooks/test-crypto-randomBytes.js
  4. +3 −0 test/async-hooks/test-emit-before-after.js
  5. +4 −0 test/async-hooks/test-enable-disable.js
  6. +4 −1 test/async-hooks/test-fseventwrap.js
  7. +3 −0 test/async-hooks/test-fsreqwrap-readFile.js
  8. +3 −0 test/async-hooks/test-getaddrinforeqwrap.js
  9. +3 −0 test/async-hooks/test-getnameinforeqwrap.js
  10. +3 −2 test/async-hooks/test-graph.signal.js
  11. +4 −1 test/async-hooks/test-no-assert-when-disabled.js
  12. +3 −0 test/async-hooks/test-pipewrap.js
  13. +4 −0 test/async-hooks/test-promise.chain-promise-before-init-hooks.js
  14. +3 −0 test/async-hooks/test-promise.js
  15. +2 −0 test/async-hooks/test-signalwrap.js
  16. +4 −1 test/async-hooks/test-statwatcher.js
  17. +12 −0 test/common/index.js
  18. +1 −1 test/known_issues/test-stdin-is-always-net.socket.js
  19. +3 −0 test/parallel/test-async-hooks-disable-during-promise.js
  20. +1 −1 test/parallel/test-async-hooks-disable-gc-tracking.js
  21. +2 −2 test/parallel/test-async-hooks-enable-during-promise.js
  22. +1 −1 test/parallel/test-async-hooks-prevent-double-destroy.js
  23. +3 −0 test/parallel/test-async-hooks-promise-triggerid.js
  24. +3 −0 test/parallel/test-async-hooks-promise.js
  25. +3 −0 test/parallel/test-async-hooks-top-level-clearimmediate.js
  26. +3 −0 test/parallel/test-async-wrap-promise-after-enabled.js
  27. +3 −0 test/parallel/test-child-process-custom-fds.js
  28. +2 −1 test/parallel/test-child-process-http-socket-leak.js
  29. +5 −1 test/parallel/test-child-process-validate-stdio.js
  30. +3 −0 test/parallel/test-cli-eval.js
  31. +2 −0 test/parallel/test-cli-node-options-disallowed.js
  32. +2 −0 test/parallel/test-cli-node-options.js
  33. +2 −0 test/parallel/test-cluster-net-listen-relative-path.js
  34. +4 −3 test/parallel/test-console.js
  35. +2 −0 test/parallel/test-cwd-enoent-preload.js
  36. +2 −0 test/parallel/test-cwd-enoent-repl.js
  37. +2 −0 test/parallel/test-cwd-enoent.js
  38. +4 −1 test/parallel/test-debug-args.js
  39. +3 −0 test/parallel/test-fs-realpath.js
  40. +3 −0 test/parallel/test-fs-write-file-sync.js
  41. +2 −2 test/parallel/test-module-cjs-helpers.js
  42. +2 −0 test/parallel/test-preload.js
  43. +4 −2 test/parallel/test-process-chdir-errormessage.js
  44. +4 −1 test/parallel/test-process-chdir.js
  45. +5 −3 test/parallel/test-process-euid-egid.js
  46. +5 −2 test/parallel/test-process-exit-handler.js
  47. +3 −0 test/parallel/test-process-fatal-exception-tick.js
  48. +6 −4 test/parallel/test-process-uid-gid.js
  49. +3 −0 test/parallel/test-process-umask-mask.js
  50. +2 −0 test/parallel/test-process-umask.js
  51. +3 −0 test/parallel/test-repl-require.js
  52. +2 −0 test/parallel/test-repl-sigint-nested-eval.js
  53. +2 −0 test/parallel/test-repl-sigint.js
  54. +3 −0 test/parallel/test-repl-tab-complete.js
  55. +2 −0 test/parallel/test-require-symlink.js
  56. +2 −0 test/parallel/test-setproctitle.js
  57. +3 −2 test/parallel/test-signal-args.js
  58. +2 −0 test/parallel/test-signal-handler.js
  59. +3 −1 test/parallel/test-stdio-pipe-access.js
  60. +3 −1 test/parallel/test-stdio-pipe-redirect.js
  61. +9 −0 test/parallel/test-timers-immediate-unref-nested-once.js
  62. +5 −0 test/parallel/test-timers-immediate-unref-simple.js
  63. +3 −0 test/parallel/test-trace-events-all.js
  64. +2 −0 test/parallel/test-trace-events-api.js
  65. +3 −0 test/parallel/test-trace-events-async-hooks.js
  66. +3 −0 test/parallel/test-trace-events-binding.js
  67. +3 −0 test/parallel/test-trace-events-bootstrap.js
  68. +3 −0 test/parallel/test-trace-events-category-used.js
  69. +3 −0 test/parallel/test-trace-events-file-pattern.js
  70. +3 −0 test/parallel/test-trace-events-fs-sync.js
  71. +3 −0 test/parallel/test-trace-events-metadata.js
  72. +3 −0 test/parallel/test-trace-events-none.js
  73. +3 −0 test/parallel/test-trace-events-perf.js
  74. +3 −0 test/parallel/test-trace-events-process-exit.js
  75. +3 −0 test/parallel/test-trace-events-v8.js
  76. +3 −0 test/parallel/test-trace-events-vm.js
  77. +4 −1 test/sequential/test-async-wrap-getasyncid.js
  78. +0 −1 test/sequential/test-buffer-creation-regression.js
  79. +3 −0 test/sequential/test-fs-watch.js
  80. +3 −0 test/sequential/test-init.js
  81. +4 −0 test/sequential/test-inspector-overwrite-config.js
  82. +3 −0 test/sequential/test-performance.js
  83. +11 −0 tools/run-worker.js
  84. +7 −0 tools/test.py
@@ -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');
@@ -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');
@@ -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');
@@ -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');
@@ -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);
@@ -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' ];
@@ -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();
@@ -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();
@@ -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();
@@ -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();
@@ -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');
@@ -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');

@@ -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();
@@ -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) {
@@ -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();
@@ -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');
@@ -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();

@@ -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 &&
@@ -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() {
@@ -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,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),
@@ -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 });
@@ -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());
@@ -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();

{
@@ -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 = [];
@@ -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 = [];

@@ -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({
@@ -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 = [];
@@ -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. ' +
@@ -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) => {
@@ -19,6 +18,8 @@ if (process.argv[2] === 'child') {
return;
}

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

let child;
let socket;

@@ -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, {
@@ -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');
}
@@ -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);
@@ -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.

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

@@ -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';
@@ -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));
}));
Oops, something went wrong.

0 comments on commit ed05d9a

Please sign in to comment.
You can’t perform that action at this time.