node/test/async-hooks/test-async-local-storage-http.js
Antoine du Hamel bfc81ca228
test: ensure assertions are reachable in test/async-hooks
PR-URL: https://github.com/nodejs/node/pull/60150
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2025-10-09 21:57:24 +00:00

22 lines
648 B
JavaScript

'use strict';
const { mustCall } = require('../common');
const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const http = require('http');
const asyncLocalStorage = new AsyncLocalStorage();
const server = http.createServer((req, res) => {
res.end('ok');
});
server.listen(0, () => {
asyncLocalStorage.run(new Map(), () => {
const store = asyncLocalStorage.getStore();
store.set('hello', 'world');
http.get({ host: 'localhost', port: server.address().port }, mustCall(() => {
assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
server.close();
}));
});
});