Skip to content

Commit de797aa

Browse files
nigrosimoneaduh95
authored andcommitted
test: check frame restore in CallbackScope
A CallbackScope must restore the async context frame that was active before it, when there was none and when there was one. Signed-off-by: Nigro Simone <nigro.simone@gmail.com> PR-URL: #66316 Refs: nodejs/performance#24 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6918256 commit de797aa

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../../common');
4+
const assert = require('assert');
5+
const { AsyncLocalStorage } = require('async_hooks');
6+
const { runInCallbackScope } = require(`./build/${common.buildType}/binding`);
7+
8+
// A CallbackScope must restore the async context frame that was active
9+
// before it, when there was none and when there was one.
10+
11+
const als = new AsyncLocalStorage();
12+
13+
runInCallbackScope({}, 0, 0, common.mustCall(() => {
14+
als.enterWith('inner');
15+
}));
16+
assert.strictEqual(als.getStore(), undefined);
17+
18+
als.run('outer', common.mustCall(() => {
19+
runInCallbackScope({}, 0, 0, common.mustCall(() => {
20+
als.enterWith('inner');
21+
}));
22+
assert.strictEqual(als.getStore(), 'outer');
23+
}));

0 commit comments

Comments
 (0)