0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 12:10:08 +01:00
nodejs/test/parallel/test-diagnostics-channel-tracing-channel-has-subscribers.js
Thomas Hunter II 36e44f1230
doc, test: tracing channel hasSubscribers getter
follow up work for https://github.com/nodejs/node/pull/51915

PR-URL: https://github.com/nodejs/node/pull/52908
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-07-24 16:48:40 +00:00

52 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
const dc = require('diagnostics_channel');
const assert = require('assert');
const handler = common.mustNotCall();
{
const handlers = {
start: common.mustNotCall()
};
const channel = dc.tracingChannel('test');
assert.strictEqual(channel.hasSubscribers, false);
channel.subscribe(handlers);
assert.strictEqual(channel.hasSubscribers, true);
channel.unsubscribe(handlers);
assert.strictEqual(channel.hasSubscribers, false);
channel.start.subscribe(handler);
assert.strictEqual(channel.hasSubscribers, true);
channel.start.unsubscribe(handler);
assert.strictEqual(channel.hasSubscribers, false);
}
{
const handlers = {
asyncEnd: common.mustNotCall()
};
const channel = dc.tracingChannel('test');
assert.strictEqual(channel.hasSubscribers, false);
channel.subscribe(handlers);
assert.strictEqual(channel.hasSubscribers, true);
channel.unsubscribe(handlers);
assert.strictEqual(channel.hasSubscribers, false);
channel.asyncEnd.subscribe(handler);
assert.strictEqual(channel.hasSubscribers, true);
channel.asyncEnd.unsubscribe(handler);
assert.strictEqual(channel.hasSubscribers, false);
}