11'use strict' ;
22
33const common = require ( '../common' ) ;
4- if ( ! common . hasCrypto )
5- common . skip ( 'missing crypto' ) ;
6-
74const assert = require ( 'assert' ) ;
85const initHooks = require ( './init-hooks' ) ;
9- const fixtures = require ( '../common/fixtures' ) ;
106const { checkInvocations } = require ( './hook-checks' ) ;
11- const tls = require ( 'tls ' ) ;
7+ const net = require ( 'net ' ) ;
128
139const hooks = initHooks ( ) ;
1410hooks . enable ( ) ;
1511
1612//
1713// Creating server and listening on port
1814//
19- const server = tls
20- . createServer ( {
21- cert : fixtures . readSync ( 'test_cert.pem' ) ,
22- key : fixtures . readSync ( 'test_key.pem' )
23- } )
15+ const server = net . createServer ( )
2416 . on ( 'listening' , common . mustCall ( onlistening ) )
25- . on ( 'secureConnection ' , common . mustCall ( onsecureConnection ) )
17+ . on ( 'connection ' , common . mustCall ( onconnection ) )
2618 . listen ( 0 ) ;
2719
2820assert . strictEqual ( hooks . activitiesOfTypes ( 'WRITEWRAP' ) . length , 0 ) ;
@@ -32,16 +24,17 @@ function onlistening() {
3224 //
3325 // Creating client and connecting it to server
3426 //
35- tls
36- . connect ( server . address ( ) . port , { rejectUnauthorized : false } )
37- . on ( 'secureConnect ' , common . mustCall ( onsecureConnect ) ) ;
27+ net
28+ . connect ( server . address ( ) . port )
29+ . on ( 'connect ' , common . mustCall ( onconnect ) ) ;
3830
3931 assert . strictEqual ( hooks . activitiesOfTypes ( 'WRITEWRAP' ) . length , 0 ) ;
4032}
4133
4234function checkDestroyedWriteWraps ( n , stage ) {
4335 const as = hooks . activitiesOfTypes ( 'WRITEWRAP' ) ;
44- assert . strictEqual ( as . length , n , `${ n } WRITEWRAPs when ${ stage } ` ) ;
36+ assert . strictEqual ( as . length , n ,
37+ `${ as . length } out of ${ n } WRITEWRAPs when ${ stage } ` ) ;
4538
4639 function checkValidWriteWrap ( w ) {
4740 assert . strictEqual ( w . type , 'WRITEWRAP' ) ;
@@ -53,41 +46,47 @@ function checkDestroyedWriteWraps(n, stage) {
5346 as . forEach ( checkValidWriteWrap ) ;
5447}
5548
56- function onsecureConnection ( ) {
49+ function onconnection ( conn ) {
50+ conn . resume ( ) ;
5751 //
5852 // Server received client connection
5953 //
60- checkDestroyedWriteWraps ( 3 , 'server got secure connection' ) ;
54+ checkDestroyedWriteWraps ( 0 , 'server got connection' ) ;
6155}
6256
63- function onsecureConnect ( ) {
57+ function onconnect ( ) {
6458 //
6559 // Client connected to server
6660 //
67- checkDestroyedWriteWraps ( 4 , 'client connected' ) ;
61+ checkDestroyedWriteWraps ( 0 , 'client connected' ) ;
6862
6963 //
7064 // Destroying client socket
7165 //
72- this . destroy ( ) ;
66+ this . write ( 'f' . repeat ( 128000 ) , ( ) => onafterwrite ( this ) ) ;
67+ }
68+
69+ function onafterwrite ( self ) {
70+ checkDestroyedWriteWraps ( 1 , 'client destroyed' ) ;
71+ self . destroy ( ) ;
7372
74- checkDestroyedWriteWraps ( 4 , 'client destroyed' ) ;
73+ checkDestroyedWriteWraps ( 1 , 'client destroyed' ) ;
7574
7675 //
7776 // Closing server
7877 //
7978 server . close ( common . mustCall ( onserverClosed ) ) ;
80- checkDestroyedWriteWraps ( 4 , 'server closing' ) ;
79+ checkDestroyedWriteWraps ( 1 , 'server closing' ) ;
8180}
8281
8382function onserverClosed ( ) {
84- checkDestroyedWriteWraps ( 4 , 'server closed' ) ;
83+ checkDestroyedWriteWraps ( 1 , 'server closed' ) ;
8584}
8685
8786process . on ( 'exit' , onexit ) ;
8887
8988function onexit ( ) {
9089 hooks . disable ( ) ;
9190 hooks . sanityCheck ( 'WRITEWRAP' ) ;
92- checkDestroyedWriteWraps ( 4 , 'process exits' ) ;
91+ checkDestroyedWriteWraps ( 1 , 'process exits' ) ;
9392}
0 commit comments