test: add AsyncLocalStorage tests using udp, tcp and tls sockets · nodejs/node@43e8650 · GitHub
Skip to content

Commit 43e8650

Browse files
RaisinTentargos
authored andcommitted
test: add AsyncLocalStorage tests using udp, tcp and tls sockets
Fixes: #40693 Signed-off-by: Darshan Sen <darshan.sen@postman.com> PR-URL: #40741 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 16ee842 commit 43e8650

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
// Regression tests for https://github.com/nodejs/node/issues/40693
6+
7+
const assert = require('assert');
8+
const net = require('net');
9+
const { AsyncLocalStorage } = require('async_hooks');
10+
11+
net
12+
.createServer((socket) => {
13+
socket.write('Hello, world!');
14+
socket.pipe(socket);
15+
})
16+
.listen(0, function() {
17+
const asyncLocalStorage = new AsyncLocalStorage();
18+
const store = { val: 'abcd' };
19+
asyncLocalStorage.run(store, () => {
20+
const client = net.connect({ port: this.address().port });
21+
client.on('data', () => {
22+
assert.deepStrictEqual(asyncLocalStorage.getStore(), store);
23+
client.end();
24+
this.close();
25+
});
26+
});
27+
});
Lines changed: 36 additions & 0 deletions

0 commit comments

Comments
 (0)