@@ -23,7 +23,7 @@ const server = http.createServer((req, res) => {
2323 setTimeout ( ( ) => {
2424 res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
2525 res . end ( 'Hello world!' ) ;
26- } , 200 ) ;
26+ } , 1200 ) ;
2727 } else if ( req . url === '/stream' ) {
2828 res . writeHead ( 200 ) ;
2929 const buffers = [ ] ;
@@ -209,19 +209,33 @@ describe('httpx', () => {
209209
210210 it ( 'timeout should ok' , async function ( ) {
211211 try {
212- await make ( server ) ( '/timeout' , { timeout : 100 } ) ;
212+ await make ( server ) ( '/timeout' , { timeout : 1000 } ) ;
213213 } catch ( ex ) {
214214 assert . strictEqual ( ex . name , 'RequestTimeoutError' ) ;
215215 const port = server . address ( ) . port ;
216- assert . strictEqual ( ex . message , `ReadTimeout(100). GET http://127.0.0.1:${ port } /timeout failed.` ) ;
216+ assert . strictEqual ( ex . message , `ReadTimeout(1000). GET http://127.0.0.1:${ port } /timeout failed.` ) ;
217+ return ;
218+ }
219+ assert . ok ( false , 'should not ok' ) ;
220+ } ) ;
221+
222+ it ( 'timeout(connectTimeout) should ok' , async function ( ) {
223+ try {
224+ await httpx . request ( 'http://100.100.100.200' , {
225+ readTimeout : 1000 ,
226+ connectTimeout : 1000
227+ } ) ;
228+ } catch ( ex ) {
229+ assert . strictEqual ( ex . name , 'RequestTimeoutError' ) ;
230+ assert . strictEqual ( ex . message , 'ConnectTimeout: Connect http://100.100.100.200 failed.' ) ;
217231 return ;
218232 }
219233 assert . ok ( false , 'should not ok' ) ;
220234 } ) ;
221235
222236 it ( 'timeout(readTimeout) should ok' , async function ( ) {
223237 try {
224- await make ( server ) ( '/readTimeout' , { readTimeout : 100 , connectTimeout : 50 } ) ;
238+ await make ( server ) ( '/readTimeout' , { readTimeout : 100 , connectTimeout : 1000 } ) ;
225239 } catch ( ex ) {
226240 assert . strictEqual ( ex . name , 'RequestTimeoutError' ) ;
227241 const port = server . address ( ) . port ;
@@ -233,7 +247,7 @@ describe('httpx', () => {
233247
234248 it ( 'timeout(readTimeout & timeout) should ok' , async function ( ) {
235249 try {
236- await make ( server ) ( '/readTimeout' , { readTimeout : 100 , connectTimeout : 50 , timeout : 300 } ) ;
250+ await make ( server ) ( '/readTimeout' , { readTimeout : 100 , connectTimeout : 1000 , timeout : 300 } ) ;
237251 } catch ( ex ) {
238252 assert . strictEqual ( ex . name , 'RequestTimeoutError' ) ;
239253 const port = server . address ( ) . port ;
0 commit comments