summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-08-01 19:01:14 -0700
committerJames M Snell <jasnell@gmail.com>2018-08-07 07:43:18 -0700
commit080316b32a0e6320e012214c32725099a0248de6 (patch)
tree8f9d6047d172e0e83c1a7a740ce3a6a2e11d26eb /test/parallel
parentfe069cca6a87bcbc7030e8a1e631a81ba8c49580 (diff)
downloadnode-new-080316b32a0e6320e012214c32725099a0248de6.tar.gz
trace_events: add node.promises category, rejection counter
Allow the trace event log to include a count of unhandled rejections and handled after rejections. This is useful primarily as a quick check to see if rejections may be going unhandled (and unnoticed in a process). PR-URL: https://github.com/nodejs/node/pull/22124 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-trace-event-promises.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/parallel/test-trace-event-promises.js b/test/parallel/test-trace-event-promises.js
new file mode 100644
index 0000000000..69d35f25ec
--- /dev/null
+++ b/test/parallel/test-trace-event-promises.js
@@ -0,0 +1,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);
+ });
+ }));
+ }));
+}