forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-trace-events-get-category-enabled-buffer.js
43 lines (30 loc) · 1.36 KB
/
test-trace-events-get-category-enabled-buffer.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
'use strict';
// Flags: --expose-internals
const common = require('../common');
const { it } = require('node:test');
try {
require('trace_events');
} catch {
common.skip('missing trace events');
}
const { createTracing, getEnabledCategories } = require('trace_events');
const assert = require('assert');
const binding = require('internal/test/binding');
const getCategoryEnabledBuffer = binding.internalBinding('trace_events').getCategoryEnabledBuffer;
it('should track enabled/disabled categories', () => {
const random = Math.random().toString().slice(2);
const category = `node.${random}`;
const buffer = getCategoryEnabledBuffer(category);
const tracing = createTracing({
categories: [category],
});
assert.ok(buffer[0] === 0, `the buffer[0] should start with value 0, got: ${buffer[0]}`);
tracing.enable();
let currentCategories = getEnabledCategories();
assert.ok(currentCategories.includes(category), `the getEnabledCategories should include ${category}, got: ${currentCategories}`);
assert.ok(buffer[0] > 0, `the buffer[0] should be greater than 0, got: ${buffer[0]}`);
tracing.disable();
currentCategories = getEnabledCategories();
assert.ok(currentCategories === undefined, `the getEnabledCategories should return undefined, got: ${currentCategories}`);
assert.ok(buffer[0] === 0, `the buffer[0] should be 0, got: ${buffer[0]}`);
});