mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
e46c680bf2
The last als.run() will reactivate the als, hence the test should test for getting the object, not undefined PR-URL: https://github.com/nodejs/node/pull/38008 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
asyncLocalStorage.run(new Map(), () => {
|
|
asyncLocalStorage.getStore().set('foo', 'bar');
|
|
process.nextTick(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('foo'), 'bar');
|
|
process.nextTick(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
});
|
|
|
|
asyncLocalStorage.disable();
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
|
|
// Calls to exit() should not mess with enabled status
|
|
asyncLocalStorage.exit(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
});
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
|
|
process.nextTick(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
asyncLocalStorage.run(new Map().set('bar', 'foo'), () => {
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('bar'), 'foo');
|
|
});
|
|
});
|
|
});
|
|
});
|