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