-
Notifications
You must be signed in to change notification settings - Fork 29.8k
/
test-trace-event-promises.js
48 lines (42 loc) · 1.46 KB
/
test-trace-event-promises.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 cp = require('child_process');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
common.disableCrashOnUnhandledRejection();
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
if (process.argv[2] === 'child') {
const p = Promise.reject(1); // Handled later
Promise.reject(2); // Unhandled
setImmediate(() => {
p.catch(() => { /* intentional noop */ });
});
} else {
tmpdir.refresh();
process.chdir(tmpdir.path);
const proc = cp.fork(__filename,
[ 'child' ], {
execArgv: [
'--no-warnings',
'--trace-event-categories',
'node.promises.rejections'
]
});
proc.once('exit', common.mustCall(() => {
const file = path.join(tmpdir.path, 'node_trace.1.log');
assert(common.fileExists(file));
fs.readFile(file, common.mustCall((err, data) => {
const traces = JSON.parse(data.toString()).traceEvents
.filter((trace) => trace.cat !== '__metadata');
traces.forEach((trace) => {
assert.strictEqual(trace.pid, proc.pid);
assert.strictEqual(trace.name, 'rejections');
assert(trace.args.unhandled <= 2);
assert(trace.args.handledAfter <= 1);
});
}));
}));
}