mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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>
This commit is contained in:
parent
0a3a60130c
commit
1b8bfddf89
26
test/async-hooks/test-async-local-storage-dgram.js
Normal file
26
test/async-hooks/test-async-local-storage-dgram.js
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
// Regression tests for https://github.com/nodejs/node/issues/40693
|
||||
|
||||
const assert = require('assert');
|
||||
const dgram = require('dgram');
|
||||
const { AsyncLocalStorage } = require('async_hooks');
|
||||
|
||||
dgram.createSocket('udp4')
|
||||
.on('message', function(msg, rinfo) { this.send(msg, rinfo.port); })
|
||||
.on('listening', function() {
|
||||
const asyncLocalStorage = new AsyncLocalStorage();
|
||||
const store = { val: 'abcd' };
|
||||
asyncLocalStorage.run(store, () => {
|
||||
const client = dgram.createSocket('udp4');
|
||||
client.on('message', (msg, rinfo) => {
|
||||
assert.deepStrictEqual(asyncLocalStorage.getStore(), store);
|
||||
client.close();
|
||||
this.close();
|
||||
});
|
||||
client.send('Hello, world!', this.address().port);
|
||||
});
|
||||
})
|
||||
.bind(0);
|
27
test/async-hooks/test-async-local-storage-socket.js
Normal file
27
test/async-hooks/test-async-local-storage-socket.js
Normal file
@ -0,0 +1,27 @@
|
||||
'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();
|
||||
});
|
||||
});
|
||||
});
|
36
test/async-hooks/test-async-local-storage-tlssocket.js
Normal file
36
test/async-hooks/test-async-local-storage-tlssocket.js
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
// Regression tests for https://github.com/nodejs/node/issues/40693
|
||||
|
||||
const assert = require('assert');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const tls = require('tls');
|
||||
const { AsyncLocalStorage } = require('async_hooks');
|
||||
|
||||
const options = {
|
||||
cert: fixtures.readKey('rsa_cert.crt'),
|
||||
key: fixtures.readKey('rsa_private.pem'),
|
||||
rejectUnauthorized: false
|
||||
};
|
||||
|
||||
tls
|
||||
.createServer(options, (socket) => {
|
||||
socket.write('Hello, world!');
|
||||
socket.pipe(socket);
|
||||
})
|
||||
.listen(0, function() {
|
||||
const asyncLocalStorage = new AsyncLocalStorage();
|
||||
const store = { val: 'abcd' };
|
||||
asyncLocalStorage.run(store, () => {
|
||||
const client = tls.connect({ port: this.address().port, ...options });
|
||||
client.on('data', () => {
|
||||
assert.deepStrictEqual(asyncLocalStorage.getStore(), store);
|
||||
client.end();
|
||||
this.close();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user