node/test/async-hooks/test-async-local-storage-http.js
Antoine du Hamel f1f6f3df84
test: ensure assertions are reached on more tests
PR-URL: https://github.com/nodejs/node/pull/60641
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-11-11 09:56:18 +00:00

22 lines
668 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, mustCall(() => {
asyncLocalStorage.run(new Map(), mustCall(() => {
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();
}));
}));
}));