node/test/async-hooks/test-async-local-storage-enable-disable.js
Darkripper214 e46c680bf2 test: improve clarity of ALS-enable-disable.js
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>
2021-04-02 18:37:35 +02:00

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');
});
});
});
});