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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
// Regression tests for https://github.com/nodejs/node/issues/40693
6+
7+
constassert=require('assert');
8+
constdgram=require('dgram');
9+
const{ AsyncLocalStorage }=require('async_hooks');
10+
11+
dgram.createSocket('udp4')
12+
.on('message',function(msg,rinfo){this.send(msg,rinfo.port);})
13+
.on('listening',function(){
14+
constasyncLocalStorage=newAsyncLocalStorage();
15+
conststore={val: 'abcd'};
16+
asyncLocalStorage.run(store,()=>{
17+
constclient=dgram.createSocket('udp4');
18+
client.on('message',(msg,rinfo)=>{
19+
assert.deepStrictEqual(asyncLocalStorage.getStore(),store);
20+
client.close();
21+
this.close();
22+
});
23+
client.send('Hello, world!',this.address().port);
24+
});
25+
})
26+
.bind(0);
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+
constassert=require('assert');
8+
constnet=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+
constasyncLocalStorage=newAsyncLocalStorage();
18+
conststore={val: 'abcd'};
19+
asyncLocalStorage.run(store,()=>{
20+
constclient=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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
if(!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
// Regression tests for https://github.com/nodejs/node/issues/40693
8+
9+
constassert=require('assert');
10+
constfixtures=require('../common/fixtures');
11+
consttls=require('tls');
12+
const{ AsyncLocalStorage }=require('async_hooks');
13+
14+
constoptions={
15+
cert: fixtures.readKey('rsa_cert.crt'),
16+
key: fixtures.readKey('rsa_private.pem'),
17+
rejectUnauthorized: false
18+
};
19+
20+
tls
21+
.createServer(options,(socket)=>{
22+
socket.write('Hello, world!');
23+
socket.pipe(socket);
24+
})
25+
.listen(0,function(){
26+
constasyncLocalStorage=newAsyncLocalStorage();
27+
conststore={val: 'abcd'};
28+
asyncLocalStorage.run(store,()=>{
29+
constclient=tls.connect({port: this.address().port, ...options});
30+
client.on('data',()=>{
31+
assert.deepStrictEqual(asyncLocalStorage.getStore(),store);
32+
client.end();
33+
this.close();
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)