mirror of https://github.com/nodejs/node.git
test: add test for async contexts in PerformanceObserver
This test proves that the PerformanceObserver callback gets called with the async context of the callsite of performance.mark()/measure() and therefore AsyncLocalStorage can be used inside a PerformanceObserver. PR: https://github.com/nodejs/node/pull/36343 PR-URL: https://github.com/nodejs/node/pull/36343 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>pull/36343/head
parent
1ea4b83912
commit
ef0f5b185d
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const {
|
||||
performance,
|
||||
PerformanceObserver,
|
||||
} = require('perf_hooks');
|
||||
const {
|
||||
executionAsyncId,
|
||||
triggerAsyncId,
|
||||
executionAsyncResource,
|
||||
} = require('async_hooks');
|
||||
|
||||
// Test Non-Buffered PerformanceObserver retains async context
|
||||
{
|
||||
const observer =
|
||||
new PerformanceObserver(common.mustCall(callback));
|
||||
|
||||
const initialAsyncId = executionAsyncId();
|
||||
let asyncIdInTimeout;
|
||||
let asyncResourceInTimeout;
|
||||
|
||||
function callback(list) {
|
||||
assert.strictEqual(triggerAsyncId(), initialAsyncId);
|
||||
assert.strictEqual(executionAsyncId(), asyncIdInTimeout);
|
||||
assert.strictEqual(executionAsyncResource(), asyncResourceInTimeout);
|
||||
observer.disconnect();
|
||||
}
|
||||
observer.observe({ entryTypes: ['mark'] });
|
||||
|
||||
setTimeout(() => {
|
||||
asyncIdInTimeout = executionAsyncId();
|
||||
asyncResourceInTimeout = executionAsyncResource();
|
||||
performance.mark('test1');
|
||||
}, 0);
|
||||
}
|
Loading…
Reference in New Issue