Skip to content

Commit 6e7b77f

Browse files
vperezmaMylesBorins
authored andcommitted
test: use mustCall in tls-connect-given-socket
PR-URL: #12592 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c10525c commit 6e7b77f

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

test/parallel/test-tls-connect-given-socket.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,20 @@ const tls = require('tls');
1111
const net = require('net');
1212
const fs = require('fs');
1313
const path = require('path');
14-
15-
let serverConnected = 0;
16-
let clientConnected = 0;
17-
1814
const options = {
1915
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
2016
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
2117
};
2218

23-
const server = tls.createServer(options, (socket) => {
24-
serverConnected++;
19+
const server = tls.createServer(options, common.mustCall((socket) => {
2520
socket.end('Hello');
26-
}).listen(0, () => {
21+
}, 2)).listen(0, common.mustCall(() => {
2722
let waiting = 2;
28-
function establish(socket) {
23+
function establish(socket, calls) {
2924
const client = tls.connect({
3025
rejectUnauthorized: false,
3126
socket: socket
32-
}, () => {
33-
clientConnected++;
27+
}, common.mustCall(() => {
3428
let data = '';
3529
client.on('data', common.mustCall((chunk) => {
3630
data += chunk.toString();
@@ -40,7 +34,7 @@ const server = tls.createServer(options, (socket) => {
4034
if (--waiting === 0)
4135
server.close();
4236
}));
43-
});
37+
}, calls));
4438
assert(client.readable);
4539
assert(client.writable);
4640

@@ -51,14 +45,14 @@ const server = tls.createServer(options, (socket) => {
5145

5246
// Immediate death socket
5347
const immediateDeath = net.connect(port);
54-
establish(immediateDeath).destroy();
48+
establish(immediateDeath, 0).destroy();
5549

5650
// Outliving
5751
const outlivingTCP = net.connect(port, common.mustCall(() => {
5852
outlivingTLS.destroy();
5953
next();
6054
}));
61-
const outlivingTLS = establish(outlivingTCP);
55+
const outlivingTLS = establish(outlivingTCP, 0);
6256

6357
function next() {
6458
// Already connected socket
@@ -70,9 +64,4 @@ const server = tls.createServer(options, (socket) => {
7064
const connecting = net.connect(port);
7165
establish(connecting);
7266
}
73-
});
74-
75-
process.on('exit', () => {
76-
assert.strictEqual(serverConnected, 2);
77-
assert.strictEqual(clientConnected, 2);
78-
});
67+
}));

0 commit comments

Comments
 (0)