@@ -6,7 +6,9 @@ if (!common.hasCrypto) {
66 common . skip ( 'missing crypto' ) ;
77 return ;
88}
9+
910const https = require ( 'https' ) ;
11+ const http = require ( 'http' ) ;
1012
1113const tls = require ( 'tls' ) ;
1214const fs = require ( 'fs' ) ;
@@ -35,83 +37,93 @@ function run() {
3537}
3638
3739test ( function serverTimeout ( cb ) {
38- const server = https . createServer ( serverOptions , function ( req , res ) {
39- // just do nothing, we should get a timeout event.
40- } ) ;
41- server . listen ( 0 , common . mustCall ( function ( ) {
40+ const server = https . createServer (
41+ serverOptions ,
42+ common . mustCall ( function ( req , res ) {
43+ // just do nothing, we should get a
44+ // timeout event.
45+ } ) ) ;
46+ server . listen ( common . mustCall ( function ( ) {
4247 const s = server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
4348 socket . destroy ( ) ;
4449 server . close ( ) ;
4550 cb ( ) ;
4651 } ) ) ;
4752 assert . ok ( s instanceof https . Server ) ;
4853 https . get ( {
49- port : this . address ( ) . port ,
54+ port : server . address ( ) . port ,
5055 rejectUnauthorized : false
5156 } ) . on ( 'error' , common . noop ) ;
5257 } ) ) ;
5358} ) ;
5459
5560test ( function serverRequestTimeout ( cb ) {
56- function handler ( req , res ) {
57- // just do nothing, we should get a timeout event.
58- req . setTimeout ( 50 , common . mustCall ( function ( ) {
59- req . socket . destroy ( ) ;
60- server . close ( ) ;
61- cb ( ) ;
61+ const server = https . createServer (
62+ serverOptions ,
63+ common . mustCall ( function ( req , res ) {
64+ // just do nothing, we should get a
65+ // timeout event.
66+ const s = req . setTimeout (
67+ 50 ,
68+ common . mustCall ( function ( socket ) {
69+ socket . destroy ( ) ;
70+ server . close ( ) ;
71+ cb ( ) ;
72+ } ) ) ;
73+ assert . ok ( s instanceof http . IncomingMessage ) ;
6274 } ) ) ;
63- }
64-
65- let server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
66- server . listen ( 0 , function ( ) {
75+ server . listen ( common . mustCall ( function ( ) {
6776 const req = https . request ( {
68- port : this . address ( ) . port ,
77+ port : server . address ( ) . port ,
6978 method : 'POST' ,
7079 rejectUnauthorized : false
7180 } ) ;
7281 req . on ( 'error' , common . noop ) ;
7382 req . write ( 'Hello' ) ;
7483 // req is in progress
75- } ) ;
84+ } ) ) ;
7685} ) ;
7786
7887test ( function serverResponseTimeout ( cb ) {
79- function handler ( req , res ) {
80- // just do nothing, we should get a timeout event.
81- res . setTimeout ( 50 , common . mustCall ( function ( ) {
82- res . socket . destroy ( ) ;
83- server . close ( ) ;
84- cb ( ) ;
88+ const server = https . createServer (
89+ serverOptions ,
90+ common . mustCall ( function ( req , res ) {
91+ // just do nothing, we should get a timeout event.
92+ const s = res . setTimeout ( 50 , common . mustCall ( function ( socket ) {
93+ socket . destroy ( ) ;
94+ server . close ( ) ;
95+ cb ( ) ;
96+ } ) ) ;
97+ assert . ok ( s instanceof http . OutgoingMessage ) ;
8598 } ) ) ;
86- }
87-
88- let server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
89- server . listen ( 0 , function ( ) {
99+ server . listen ( common . mustCall ( function ( ) {
90100 https . get ( {
91- port : this . address ( ) . port ,
101+ port : server . address ( ) . port ,
92102 rejectUnauthorized : false
93- } ) . on ( 'error' , common . noop ) ;
94- } ) ;
103+ } ) . on ( 'error' , common . mustCall ( ) ) ;
104+ } ) ) ;
95105} ) ;
96106
97107test ( function serverRequestNotTimeoutAfterEnd ( cb ) {
98- function handler ( req , res ) {
99- // just do nothing, we should get a timeout event.
100- req . setTimeout ( 50 , common . mustNotCall ( ) ) ;
101- res . on ( 'timeout' , common . mustCall ( function ( socket ) { } ) ) ;
102- }
103- const server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
104- server . on ( 'timeout' , function ( socket ) {
108+ const server = https . createServer (
109+ serverOptions ,
110+ common . mustCall ( function ( req , res ) {
111+ // just do nothing, we should get a timeout event.
112+ const s = req . setTimeout ( 50 , common . mustNotCall ( ) ) ;
113+ assert . ok ( s instanceof http . IncomingMessage ) ;
114+ res . on ( 'timeout' , common . mustCall ( ) ) ;
115+ } ) ) ;
116+ server . on ( 'timeout' , common . mustCall ( function ( socket ) {
105117 socket . destroy ( ) ;
106118 server . close ( ) ;
107119 cb ( ) ;
108- } ) ;
109- server . listen ( 0 , function ( ) {
120+ } ) ) ;
121+ server . listen ( common . mustCall ( function ( ) {
110122 https . get ( {
111- port : this . address ( ) . port ,
123+ port : server . address ( ) . port ,
112124 rejectUnauthorized : false
113- } ) . on ( 'error' , common . noop ) ;
114- } ) ;
125+ } ) . on ( 'error' , common . mustCall ( ) ) ;
126+ } ) ) ;
115127} ) ;
116128
117129test ( function serverResponseTimeoutWithPipeline ( cb ) {
@@ -123,9 +135,10 @@ test(function serverResponseTimeoutWithPipeline(cb) {
123135 const server = https . createServer ( serverOptions , function ( req , res ) {
124136 if ( req . url === '/2' )
125137 secReceived = true ;
126- res . setTimeout ( 50 , function ( ) {
138+ const s = res . setTimeout ( 50 , function ( ) {
127139 caughtTimeout += req . url ;
128140 } ) ;
141+ assert . ok ( s instanceof http . OutgoingMessage ) ;
129142 if ( req . url === '/1' ) res . end ( ) ;
130143 } ) ;
131144 server . on ( 'timeout' , function ( socket ) {
@@ -135,9 +148,9 @@ test(function serverResponseTimeoutWithPipeline(cb) {
135148 cb ( ) ;
136149 }
137150 } ) ;
138- server . listen ( 0 , function ( ) {
151+ server . listen ( common . mustCall ( function ( ) {
139152 const options = {
140- port : this . address ( ) . port ,
153+ port : server . address ( ) . port ,
141154 allowHalfOpen : true ,
142155 rejectUnauthorized : false
143156 } ;
@@ -146,30 +159,32 @@ test(function serverResponseTimeoutWithPipeline(cb) {
146159 c . write ( 'GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
147160 c . write ( 'GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
148161 } ) ;
149- } ) ;
162+ } ) ) ;
150163} ) ;
151164
152165test ( function idleTimeout ( cb ) {
153- const server = https . createServer ( serverOptions ,
154- common . mustCall ( function ( req , res ) {
155- req . on ( 'timeout' , common . mustNotCall ( ) ) ;
156- res . on ( 'timeout' , common . mustNotCall ( ) ) ;
157- res . end ( ) ;
158- } ) ) ;
159- server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
166+ const server = https . createServer (
167+ serverOptions ,
168+ common . mustCall ( function ( req , res ) {
169+ req . on ( 'timeout' , common . mustNotCall ( ) ) ;
170+ res . on ( 'timeout' , common . mustNotCall ( ) ) ;
171+ res . end ( ) ;
172+ } ) ) ;
173+ const s = server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
160174 socket . destroy ( ) ;
161175 server . close ( ) ;
162176 cb ( ) ;
163177 } ) ) ;
164- server . listen ( 0 , function ( ) {
178+ assert . ok ( s instanceof https . Server ) ;
179+ server . listen ( common . mustCall ( function ( ) {
165180 const options = {
166- port : this . address ( ) . port ,
181+ port : server . address ( ) . port ,
167182 allowHalfOpen : true ,
168183 rejectUnauthorized : false
169184 } ;
170185 tls . connect ( options , function ( ) {
171186 this . write ( 'GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
172187 // Keep-Alive
173188 } ) ;
174- } ) ;
189+ } ) ) ;
175190} ) ;
0 commit comments