Skip to content

Commit ebd1042

Browse files
author
Stephen Belanger
committed
test: test tracing channel run stores behaviour
1 parent 69743d2 commit ebd1042

3 files changed

Lines changed: 74 additions & 0 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { AsyncLocalStorage } = require('async_hooks');
5+
const dc = require('diagnostics_channel');
6+
const assert = require('assert');
7+
8+
const channel = dc.tracingChannel('test');
9+
const store = new AsyncLocalStorage();
10+
11+
const firstContext = { foo: 'bar' };
12+
const secondContext = { baz: 'buz' };
13+
14+
channel.start.bindStore(store, common.mustCall(() => {
15+
return firstContext;
16+
}));
17+
18+
channel.asyncStart.bindStore(store, common.mustCall(() => {
19+
return secondContext;
20+
}));
21+
22+
assert.strictEqual(store.getStore(), undefined);
23+
channel.traceCallback(common.mustCall((cb) => {
24+
assert.deepStrictEqual(store.getStore(), firstContext);
25+
setImmediate(cb);
26+
}), 0, {}, null, common.mustCall(() => {
27+
assert.deepStrictEqual(store.getStore(), secondContext);
28+
}));
29+
assert.strictEqual(store.getStore(), undefined);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { setTimeout } = require('node:timers/promises');
5+
const { AsyncLocalStorage } = require('async_hooks');
6+
const dc = require('diagnostics_channel');
7+
const assert = require('assert');
8+
9+
const channel = dc.tracingChannel('test');
10+
const store = new AsyncLocalStorage();
11+
12+
const context = { foo: 'bar' };
13+
14+
channel.start.bindStore(store, common.mustCall(() => {
15+
return context;
16+
}));
17+
18+
assert.strictEqual(store.getStore(), undefined);
19+
channel.tracePromise(common.mustCall(async () => {
20+
assert.deepStrictEqual(store.getStore(), context);
21+
await setTimeout(1);
22+
assert.deepStrictEqual(store.getStore(), context);
23+
}));
24+
assert.strictEqual(store.getStore(), undefined);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { AsyncLocalStorage } = require('async_hooks');
5+
const dc = require('diagnostics_channel');
6+
const assert = require('assert');
7+
8+
const channel = dc.tracingChannel('test');
9+
const store = new AsyncLocalStorage();
10+
11+
const context = { foo: 'bar' };
12+
13+
channel.start.bindStore(store, common.mustCall(() => {
14+
return context;
15+
}));
16+
17+
assert.strictEqual(store.getStore(), undefined);
18+
channel.traceSync(common.mustCall(() => {
19+
assert.deepStrictEqual(store.getStore(), context);
20+
}));
21+
assert.strictEqual(store.getStore(), undefined);

0 commit comments

Comments
 (0)