summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Ijaz Sheikh <ofrobots@google.com>2018-08-02 17:13:21 -0700
committerMichaƫl Zasso <targos@protonmail.com>2018-09-04 14:26:51 +0200
commit8e9121530711414586075186879ce3f7bada4125 (patch)
treec235e6c2786dec98df79ace29b07f950755bbedd
parentec285c8c6697e2b415addd81fddafd81980f8b2c (diff)
downloadnode-new-8e9121530711414586075186879ce3f7bada4125.tar.gz
test: add test to dynamic enablement of trace-events
PR-URL: https://github.com/nodejs/node/pull/22114 Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--test/parallel/test-trace-events-dynamic-enable.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/parallel/test-trace-events-dynamic-enable.js b/test/parallel/test-trace-events-dynamic-enable.js
new file mode 100644
index 0000000000..a32949f8ec
--- /dev/null
+++ b/test/parallel/test-trace-events-dynamic-enable.js
@@ -0,0 +1,58 @@
+'use strict';
+
+const common = require('../common');
+
+common.skipIfInspectorDisabled();
+
+const assert = require('assert');
+const { performance } = require('perf_hooks');
+const { Session } = require('inspector');
+
+const session = new Session();
+
+function post(message, data) {
+ return new Promise((resolve, reject) => {
+ session.post(message, data, (err, result) => {
+ if (err)
+ reject(new Error(JSON.stringify(err)));
+ else
+ resolve(result);
+ });
+ });
+}
+
+async function test() {
+ session.connect();
+
+ let traceNotification = null;
+ let tracingComplete = false;
+ session.on('NodeTracing.dataCollected', (n) => traceNotification = n);
+ session.on('NodeTracing.tracingComplete', () => tracingComplete = true);
+
+ // Generate a node.perf event before tracing is enabled.
+ performance.mark('mark1');
+
+ const traceConfig = { includedCategories: ['node.perf'] };
+ await post('NodeTracing.start', { traceConfig });
+
+ // Generate a node.perf event after tracing is enabled. This should be the
+ // mark event captured.
+ performance.mark('mark2');
+
+ await post('NodeTracing.stop', { traceConfig });
+
+ performance.mark('mark3');
+
+ session.disconnect();
+
+ assert.ok(tracingComplete);
+ assert.ok(traceNotification);
+ assert.ok(traceNotification.data && traceNotification.data.value);
+
+ const events = traceNotification.data.value;
+ const marks = events.filter((t) => null !== /node\.perf\.usertim/.exec(t.cat));
+ assert.strictEqual(marks.length, 1);
+ assert.strictEqual(marks[0].name, 'mark2');
+}
+
+test();