Skip to content

Commit e048b15

Browse files
juggernaut451BridgeAR
authored andcommitted
test: refactor parallel/test-tls-delayed-attach
test: refactor parallel/test-tls-delayed-attach Added description to the test, replace function with arrow function and implemented common.mustCall PR-URL: #19421 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 49fd9c6 commit e048b15

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

test/parallel/test-tls-delayed-attach.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const common = require('../common');
2424
if (!common.hasCrypto)
2525
common.skip('missing crypto');
2626

27+
// This test tries to confirm that a TLS Socket will work as expected even if it
28+
// is created after the original socket has received some data.
29+
//
30+
// Ref: https://github.com/nodejs/node-v0.x-archive/issues/6940
31+
// Ref: https://github.com/nodejs/node-v0.x-archive/pull/6950
32+
2733
const fixtures = require('../common/fixtures');
2834
const assert = require('assert');
2935
const tls = require('tls');
@@ -37,30 +43,30 @@ const options = {
3743
cert: fixtures.readKey('agent1-cert.pem')
3844
};
3945

40-
const server = net.createServer(function(c) {
46+
const server = net.createServer(common.mustCall((c) => {
4147
setTimeout(function() {
4248
const s = new tls.TLSSocket(c, {
4349
isServer: true,
4450
secureContext: tls.createSecureContext(options)
4551
});
4652

47-
s.on('data', function(chunk) {
53+
s.on('data', (chunk) => {
4854
received += chunk;
4955
});
5056

51-
s.on('end', function() {
57+
s.on('end', common.mustCall(() => {
5258
server.close();
5359
s.destroy();
54-
});
60+
}));
5561
}, 200);
56-
}).listen(0, function() {
57-
const c = tls.connect(this.address().port, {
62+
})).listen(0, common.mustCall(() => {
63+
const c = tls.connect(server.address().port, {
5864
rejectUnauthorized: false
59-
}, function() {
65+
}, () => {
6066
c.end(sent);
6167
});
62-
});
68+
}));
6369

64-
process.on('exit', function() {
70+
process.on('exit', () => {
6571
assert.strictEqual(received, sent);
6672
});

0 commit comments

Comments
 (0)