• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const { Worker, parentPort } = require('worker_threads');
5
6// Do not use isMainThread so that this test itself can be run inside a Worker.
7if (!process.env.HAS_STARTED_WORKER) {
8  process.env.HAS_STARTED_WORKER = 1;
9  process.env.NODE_CHANNEL_FD = 'foo'; // Make worker think it has IPC.
10  const w = new Worker(__filename);
11  w.on('message', common.mustCall((message) => {
12    assert.strictEqual(message, true);
13  }));
14} else {
15  {
16    const before = process.title;
17    process.title += ' in worker';
18    assert.strictEqual(process.title, before);
19  }
20
21  {
22    const before = process.debugPort;
23    process.debugPort++;
24    assert.strictEqual(process.debugPort, before);
25  }
26
27  {
28    const mask = 0o600;
29    assert.throws(() => { process.umask(mask); }, {
30      code: 'ERR_WORKER_UNSUPPORTED_OPERATION',
31      message: 'Setting process.umask() is not supported in workers'
32    });
33  }
34
35  const stubs = ['abort', 'chdir', 'send', 'disconnect'];
36
37  if (!common.isWindows) {
38    stubs.push('setuid', 'seteuid', 'setgid',
39               'setegid', 'setgroups', 'initgroups');
40  }
41
42  stubs.forEach((fn) => {
43    assert.strictEqual(process[fn].disabled, true);
44    assert.throws(() => {
45      process[fn]();
46    }, {
47      code: 'ERR_WORKER_UNSUPPORTED_OPERATION',
48      message: `process.${fn}() is not supported in workers`
49    });
50  });
51
52  ['channel', 'connected'].forEach((fn) => {
53    assert.throws(() => {
54      process[fn]; // eslint-disable-line no-unused-expressions
55    }, {
56      code: 'ERR_WORKER_UNSUPPORTED_OPERATION',
57      message: `process.${fn} is not supported in workers`
58    });
59  });
60
61  assert.strictEqual('_startProfilerIdleNotifier' in process, false);
62  assert.strictEqual('_stopProfilerIdleNotifier' in process, false);
63  assert.strictEqual('_debugProcess' in process, false);
64  assert.strictEqual('_debugPause' in process, false);
65  assert.strictEqual('_debugEnd' in process, false);
66
67  parentPort.postMessage(true);
68}
69