0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/async-hooks/test-async-local-storage-socket.js
Darshan Sen 1b8bfddf89 test: add AsyncLocalStorage tests using udp, tcp and tls sockets
Fixes: https://github.com/nodejs/node/issues/40693

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: https://github.com/nodejs/node/pull/40741
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2021-11-18 18:42:23 +05:30

28 lines
714 B
JavaScript

'use strict';
require('../common');
// Regression tests for https://github.com/nodejs/node/issues/40693
const assert = require('assert');
const net = require('net');
const { AsyncLocalStorage } = require('async_hooks');
net
.createServer((socket) => {
socket.write('Hello, world!');
socket.pipe(socket);
})
.listen(0, function() {
const asyncLocalStorage = new AsyncLocalStorage();
const store = { val: 'abcd' };
asyncLocalStorage.run(store, () => {
const client = net.connect({ port: this.address().port });
client.on('data', () => {
assert.deepStrictEqual(asyncLocalStorage.getStore(), store);
client.end();
this.close();
});
});
});