-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-worker-cpu-profile.js
More file actions
56 lines (50 loc) · 1.32 KB
/
test-worker-cpu-profile.js
File metadata and controls
56 lines (50 loc) · 1.32 KB
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
49
50
51
52
53
54
55
56
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
const worker = new Worker(`
const { parentPort } = require('worker_threads');
parentPort.on('message', () => {});
`, { eval: true });
worker.on('online', common.mustCall(async () => {
{
const handle = await worker.startCpuProfile();
JSON.parse(await handle.stop());
// Stop again
JSON.parse(await handle.stop());
}
{
const handle = await worker.startCpuProfile({
sampleInterval: 0.5,
maxBufferSize: 8,
});
JSON.parse(await handle.stop());
}
{
const [handle1, handle2] = await Promise.all([
worker.startCpuProfile(),
worker.startCpuProfile(),
]);
const [profile1, profile2] = await Promise.all([
handle1.stop(),
handle2.stop(),
]);
JSON.parse(profile1);
JSON.parse(profile2);
}
{
await worker.startCpuProfile();
// It will be stopped automatically when the worker is terminated
}
worker.terminate();
}));
worker.once('exit', common.mustCall(async () => {
assert.throws(
() => worker.startCpuProfile({ maxBufferSize: 0 }),
common.expectsError({
code: 'ERR_OUT_OF_RANGE',
}));
await assert.rejects(worker.startCpuProfile(), {
code: 'ERR_WORKER_NOT_RUNNING'
});
}));