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

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

‎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
constnet=require('net');
1212
constfs=require('fs');
1313
constpath=require('path');
14-
15-
letserverConnected=0;
16-
letclientConnected=0;
17-
1814
constoptions={
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-
constserver=tls.createServer(options,(socket)=>{
24-
serverConnected++;
19+
constserver=tls.createServer(options,common.mustCall((socket)=>{
2520
socket.end('Hello');
26-
}).listen(0,()=>{
21+
},2)).listen(0,common.mustCall(()=>{
2722
letwaiting=2;
28-
functionestablish(socket){
23+
functionestablish(socket,calls){
2924
constclient=tls.connect({
3025
rejectUnauthorized: false,
3126
socket: socket
32-
},()=>{
33-
clientConnected++;
27+
},common.mustCall(()=>{
3428
letdata='';
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
constimmediateDeath=net.connect(port);
54-
establish(immediateDeath).destroy();
48+
establish(immediateDeath,0).destroy();
5549

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

6357
functionnext(){
6458
// Already connected socket
@@ -70,9 +64,4 @@ const server = tls.createServer(options, (socket) => {
7064
constconnecting=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)