-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-async-local-storage-tlssocket.js
More file actions
36 lines (31 loc) · 1.02 KB
/
test-async-local-storage-tlssocket.js
File metadata and controls
36 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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, common.mustCall(function() {
const asyncLocalStorage = new AsyncLocalStorage();
const store = { val: 'abcd' };
asyncLocalStorage.run(store, common.mustCall(() => {
const client = tls.connect({ port: this.address().port, ...options });
client.on('data', common.mustCall(() => {
assert.deepStrictEqual(asyncLocalStorage.getStore(), store);
client.end();
this.close();
}));
}));
}));