Skip to content

Commit 72e3dda

Browse files
vperezmaTrott
authored andcommitted
test: use mustCall in tls-connect-given-socket
PR-URL: #12592 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b7bc09f commit 72e3dda

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

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

+8-19
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,20 @@ const tls = require('tls');
3232
const net = require('net');
3333
const fs = require('fs');
3434
const path = require('path');
35-
36-
let serverConnected = 0;
37-
let clientConnected = 0;
38-
3935
const options = {
4036
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
4137
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
4238
};
4339

44-
const server = tls.createServer(options, (socket) => {
45-
serverConnected++;
40+
const server = tls.createServer(options, common.mustCall((socket) => {
4641
socket.end('Hello');
47-
}).listen(0, () => {
42+
}, 2)).listen(0, common.mustCall(() => {
4843
let waiting = 2;
49-
function establish(socket) {
44+
function establish(socket, calls) {
5045
const client = tls.connect({
5146
rejectUnauthorized: false,
5247
socket: socket
53-
}, () => {
54-
clientConnected++;
48+
}, common.mustCall(() => {
5549
let data = '';
5650
client.on('data', common.mustCall((chunk) => {
5751
data += chunk.toString();
@@ -61,7 +55,7 @@ const server = tls.createServer(options, (socket) => {
6155
if (--waiting === 0)
6256
server.close();
6357
}));
64-
});
58+
}, calls));
6559
assert(client.readable);
6660
assert(client.writable);
6761

@@ -72,14 +66,14 @@ const server = tls.createServer(options, (socket) => {
7266

7367
// Immediate death socket
7468
const immediateDeath = net.connect(port);
75-
establish(immediateDeath).destroy();
69+
establish(immediateDeath, 0).destroy();
7670

7771
// Outliving
7872
const outlivingTCP = net.connect(port, common.mustCall(() => {
7973
outlivingTLS.destroy();
8074
next();
8175
}));
82-
const outlivingTLS = establish(outlivingTCP);
76+
const outlivingTLS = establish(outlivingTCP, 0);
8377

8478
function next() {
8579
// Already connected socket
@@ -91,9 +85,4 @@ const server = tls.createServer(options, (socket) => {
9185
const connecting = net.connect(port);
9286
establish(connecting);
9387
}
94-
});
95-
96-
process.on('exit', () => {
97-
assert.strictEqual(serverConnected, 2);
98-
assert.strictEqual(clientConnected, 2);
99-
});
88+
}));

0 commit comments

Comments
 (0)