1
1
'use strict' ;
2
2
3
3
const common = require ( '../common' ) ;
4
- if ( ! common . hasCrypto )
5
- common . skip ( 'missing crypto' ) ;
6
-
7
4
const assert = require ( 'assert' ) ;
8
5
const initHooks = require ( './init-hooks' ) ;
9
- const fixtures = require ( '../common/fixtures' ) ;
10
6
const { checkInvocations } = require ( './hook-checks' ) ;
11
- const tls = require ( 'tls ' ) ;
7
+ const net = require ( 'net ' ) ;
12
8
13
9
const hooks = initHooks ( ) ;
14
10
hooks . enable ( ) ;
15
11
16
12
//
17
13
// Creating server and listening on port
18
14
//
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 ( )
24
16
. on ( 'listening' , common . mustCall ( onlistening ) )
25
- . on ( 'secureConnection ' , common . mustCall ( onsecureConnection ) )
17
+ . on ( 'connection ' , common . mustCall ( onconnection ) )
26
18
. listen ( 0 ) ;
27
19
28
20
assert . strictEqual ( hooks . activitiesOfTypes ( 'WRITEWRAP' ) . length , 0 ) ;
@@ -32,16 +24,17 @@ function onlistening() {
32
24
//
33
25
// Creating client and connecting it to server
34
26
//
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 ) ) ;
38
30
39
31
assert . strictEqual ( hooks . activitiesOfTypes ( 'WRITEWRAP' ) . length , 0 ) ;
40
32
}
41
33
42
34
function checkDestroyedWriteWraps ( n , stage ) {
43
35
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 } ` ) ;
45
38
46
39
function checkValidWriteWrap ( w ) {
47
40
assert . strictEqual ( w . type , 'WRITEWRAP' ) ;
@@ -53,41 +46,47 @@ function checkDestroyedWriteWraps(n, stage) {
53
46
as . forEach ( checkValidWriteWrap ) ;
54
47
}
55
48
56
- function onsecureConnection ( ) {
49
+ function onconnection ( conn ) {
50
+ conn . resume ( ) ;
57
51
//
58
52
// Server received client connection
59
53
//
60
- checkDestroyedWriteWraps ( 3 , 'server got secure connection' ) ;
54
+ checkDestroyedWriteWraps ( 0 , 'server got connection' ) ;
61
55
}
62
56
63
- function onsecureConnect ( ) {
57
+ function onconnect ( ) {
64
58
//
65
59
// Client connected to server
66
60
//
67
- checkDestroyedWriteWraps ( 4 , 'client connected' ) ;
61
+ checkDestroyedWriteWraps ( 0 , 'client connected' ) ;
68
62
69
63
//
70
64
// Destroying client socket
71
65
//
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 ( ) ;
73
72
74
- checkDestroyedWriteWraps ( 4 , 'client destroyed' ) ;
73
+ checkDestroyedWriteWraps ( 1 , 'client destroyed' ) ;
75
74
76
75
//
77
76
// Closing server
78
77
//
79
78
server . close ( common . mustCall ( onserverClosed ) ) ;
80
- checkDestroyedWriteWraps ( 4 , 'server closing' ) ;
79
+ checkDestroyedWriteWraps ( 1 , 'server closing' ) ;
81
80
}
82
81
83
82
function onserverClosed ( ) {
84
- checkDestroyedWriteWraps ( 4 , 'server closed' ) ;
83
+ checkDestroyedWriteWraps ( 1 , 'server closed' ) ;
85
84
}
86
85
87
86
process . on ( 'exit' , onexit ) ;
88
87
89
88
function onexit ( ) {
90
89
hooks . disable ( ) ;
91
90
hooks . sanityCheck ( 'WRITEWRAP' ) ;
92
- checkDestroyedWriteWraps ( 4 , 'process exits' ) ;
91
+ checkDestroyedWriteWraps ( 1 , 'process exits' ) ;
93
92
}
0 commit comments