/
test-trace-events-threadpool.js
71 lines (61 loc) · 1.81 KB
/
test-trace-events-threadpool.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
if (!common.hasCrypto)
common.skip('missing crypto');
const { hkdf } = require('crypto');
const { deflate } = require('zlib');
const { Blob } = require('buffer');
if (process.env.isChild === '1') {
hkdf('sha512', 'key', 'salt', 'info', 64, () => {});
deflate('hello', () => {});
// Make async call
const blob = new Blob(['h'.repeat(4096 * 2)]);
blob.arrayBuffer();
return;
}
tmpdir.refresh();
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
cp.spawnSync(process.execPath,
[
'--trace-events-enabled',
'--trace-event-categories',
'node.threadpoolwork.sync,node.threadpoolwork.async',
__filename,
],
{
cwd: tmpdir.path,
env: {
...process.env,
isChild: '1',
},
});
assert(fs.existsSync(FILE_NAME));
const data = fs.readFileSync(FILE_NAME);
const traces = JSON.parse(data.toString()).traceEvents;
assert(traces.length > 0);
let blobCount = 0;
let zlibCount = 0;
let cryptoCount = 0;
traces.forEach((item) => {
if ([
'node,node.threadpoolwork,node.threadpoolwork.sync',
'node,node.threadpoolwork,node.threadpoolwork.async',
].includes(item.cat)) {
if (item.name === 'blob') {
blobCount++;
} else if (item.name === 'zlib') {
zlibCount++;
} else if (item.name === 'crypto') {
cryptoCount++;
}
}
});
// There are three types, each type has two async events and sync events at least
assert.ok(blobCount >= 4);
assert.ok(zlibCount >= 4);
assert.ok(cryptoCount >= 4);