@@ -11,26 +11,20 @@ const tls = require('tls');
1111const net = require ( 'net' ) ;
1212const fs = require ( 'fs' ) ;
1313const path = require ( 'path' ) ;
14-
15- let serverConnected = 0 ;
16- let clientConnected = 0 ;
17-
1814const options = {
1915key : fs . readFileSync ( path . join ( common . fixturesDir , 'test_key.pem' ) ) ,
2016cert : 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 ) => {
2520socket . end ( 'Hello' ) ;
26- } ) . listen ( 0 , ( ) => {
21+ } , 2 ) ) . listen ( 0 , common . mustCall ( ( ) => {
2722let waiting = 2 ;
28- function establish ( socket ) {
23+ function establish ( socket , calls ) {
2924const client = tls . connect ( {
3025rejectUnauthorized : false ,
3126socket : socket
32- } , ( ) => {
33- clientConnected ++ ;
27+ } , common . mustCall ( ( ) => {
3428let data = '' ;
3529client . on ( 'data' , common . mustCall ( ( chunk ) => {
3630data += chunk . toString ( ) ;
@@ -40,7 +34,7 @@ const server = tls.createServer(options, (socket) => {
4034if ( -- waiting === 0 )
4135server . close ( ) ;
4236} ) ) ;
43- } ) ;
37+ } , calls ) ) ;
4438assert ( client . readable ) ;
4539assert ( client . writable ) ;
4640
@@ -51,14 +45,14 @@ const server = tls.createServer(options, (socket) => {
5145
5246// Immediate death socket
5347const immediateDeath = net . connect ( port ) ;
54- establish ( immediateDeath ) . destroy ( ) ;
48+ establish ( immediateDeath , 0 ) . destroy ( ) ;
5549
5650// Outliving
5751const outlivingTCP = net . connect ( port , common . mustCall ( ( ) => {
5852outlivingTLS . destroy ( ) ;
5953next ( ) ;
6054} ) ) ;
61- const outlivingTLS = establish ( outlivingTCP ) ;
55+ const outlivingTLS = establish ( outlivingTCP , 0 ) ;
6256
6357function next ( ) {
6458// Already connected socket
@@ -70,9 +64,4 @@ const server = tls.createServer(options, (socket) => {
7064const connecting = net . connect ( port ) ;
7165establish ( connecting ) ;
7266}
73- } ) ;
74-
75- process . on ( 'exit' , ( ) => {
76- assert . strictEqual ( serverConnected , 2 ) ;
77- assert . strictEqual ( clientConnected , 2 ) ;
78- } ) ;
67+ } ) ) ;
0 commit comments