• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const { Worker } = require('worker_threads');
5const { once } = require('events');
6const helper = require('../common/report');
7
8async function basic() {
9  // Test that the report includes basic information about Worker threads.
10
11  const w = new Worker(`
12    const { parentPort } = require('worker_threads');
13    parentPort.once('message', () => {
14      /* Wait for message to stop the Worker */
15    });
16  `, { eval: true });
17
18  await once(w, 'online');
19
20  const report = process.report.getReport();
21  helper.validateContent(report);
22  assert.strictEqual(report.workers.length, 1);
23  helper.validateContent(report.workers[0]);
24  assert.strictEqual(report.workers[0].header.threadId, w.threadId);
25
26  w.postMessage({});
27
28  await once(w, 'exit');
29}
30
31async function interruptingJS() {
32  // Test that the report also works when Worker threads are busy in JS land.
33
34  const w = new Worker('while (true);', { eval: true });
35
36  await once(w, 'online');
37
38  const report = process.report.getReport();
39  helper.validateContent(report);
40  assert.strictEqual(report.workers.length, 1);
41  helper.validateContent(report.workers[0]);
42
43  await w.terminate();
44}
45
46(async function() {
47  await basic();
48  await interruptingJS();
49})().then(common.mustCall());
50