mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
PR-URL: https://github.com/nodejs/node/pull/59873 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
25 lines
890 B
JavaScript
25 lines
890 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { Readable, finished } = require('stream');
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
const { strictEqual } = require('assert');
|
|
const AsyncContextFrame = require('internal/async_context_frame');
|
|
const internalAsyncHooks = require('internal/async_hooks');
|
|
|
|
// This test verifies that ALS context is preserved when using stream.finished()
|
|
|
|
const als = new AsyncLocalStorage();
|
|
const readable = new Readable();
|
|
|
|
als.run('test-context-1', () => {
|
|
finished(readable, common.mustCall(() => {
|
|
strictEqual(AsyncContextFrame.enabled || internalAsyncHooks.getHookArrays()[0].length > 0,
|
|
true, 'One of AsyncContextFrame or async hooks criteria should be met');
|
|
strictEqual(als.getStore(), 'test-context-1', 'ALS context should be preserved');
|
|
}));
|
|
});
|
|
|
|
readable.destroy();
|