@@ -22,7 +22,10 @@ function execCLI(args, options) {
22
22
return childProcess . spawn ( process . execPath , fullArgs , options ) ;
23
23
}
24
24
25
- const FAST_OPTS = '-t 1000 -i 100 -w 100' . split ( ' ' ) ;
25
+
26
+ const FAST_OPTS = '-t 1000 -i 100 -w 100' . split ( ' ' ) ;
27
+ const FAST_OPTS_TIMEOUT_UNIT = '-t 1s -i 100 -w 100' . split ( ' ' ) ;
28
+
26
29
27
30
describe ( 'cli' , function ( ) {
28
31
this . timeout ( 3000 ) ;
@@ -271,6 +274,22 @@ describe('cli', function () {
271
274
} ) ;
272
275
} ) ;
273
276
277
+ it ( 'should timeout when all resources are not available and timout option is specified with unit' , function ( done ) {
278
+ temp . mkdir ( { } , function ( err , dirPath ) {
279
+ if ( err ) return done ( err ) ;
280
+ const opts = {
281
+ resources : [ path . resolve ( dirPath , 'foo' ) ] ,
282
+ timeout : '1s'
283
+ } ;
284
+ // timeout is in FAST_OPTS
285
+ execCLI ( opts . resources . concat ( FAST_OPTS_TIMEOUT_UNIT ) , { } ) . on ( 'exit' , function ( code ) {
286
+ expect ( code ) . toNotBe ( 0 ) ;
287
+ done ( ) ;
288
+ } ) ;
289
+ } ) ;
290
+ } ) ;
291
+
292
+
274
293
it ( 'should timeout when some resources are not available and timout option is specified' , function ( done ) {
275
294
temp . mkdir ( { } , function ( err , dirPath ) {
276
295
if ( err ) return done ( err ) ;
@@ -349,6 +368,31 @@ describe('cli', function () {
349
368
} ) ;
350
369
} ) ;
351
370
371
+ it ( 'should timeout when an http resource does not respond before httpTimeout specified with unit' , function ( done ) {
372
+ const opts = {
373
+ resources : [ 'http://localhost:8125' ] ,
374
+ timeout : 1000 ,
375
+ interval : 100 ,
376
+ window : 100 ,
377
+ httpTimeout : '70ms'
378
+ } ;
379
+
380
+ httpServer = http . createServer ( ) . on ( 'request' , function ( req , res ) {
381
+ // make it a slow response, longer than the httpTimeout
382
+ setTimeout ( function ( ) {
383
+ res . end ( 'data' ) ;
384
+ } , 90 ) ;
385
+ } ) ;
386
+ httpServer . listen ( 8125 , 'localhost' ) ;
387
+
388
+ const addOpts = '--httpTimeout 70ms' . split ( ' ' ) ;
389
+ // timeout, interval, and window are in FAST_OPTS
390
+ execCLI ( opts . resources . concat ( FAST_OPTS ) . concat ( addOpts ) , { } ) . on ( 'exit' , function ( code ) {
391
+ expect ( code ) . toNotBe ( 0 ) ;
392
+ done ( ) ;
393
+ } ) ;
394
+ } ) ;
395
+
352
396
it ( 'should timeout when an http GET resource is not available' , function ( done ) {
353
397
const opts = {
354
398
resources : [ 'http-get://localhost:3999' ] ,
@@ -422,6 +466,21 @@ describe('cli', function () {
422
466
} ) ;
423
467
} ) ;
424
468
469
+ it ( 'should timeout when a service host is unreachable, tcpTimeout specified with unit' , function ( done ) {
470
+ const opts = {
471
+ resources : [ 'tcp:256.0.0.1:1234' ] ,
472
+ timeout : 1000 ,
473
+ tcpTimeout : '1s'
474
+ } ;
475
+
476
+ const addOpts = '--tcpTimeout 1s' . split ( ' ' ) ;
477
+ // timeout is in FAST_OPTS
478
+ execCLI ( opts . resources . concat ( FAST_OPTS ) . concat ( addOpts ) , { } ) . on ( 'exit' , function ( code ) {
479
+ expect ( code ) . toNotBe ( 0 ) ;
480
+ done ( ) ;
481
+ } ) ;
482
+ } ) ;
483
+
425
484
it ( 'should timeout when a service is not listening to a socket' , function ( done ) {
426
485
let socketPath ;
427
486
temp . mkdir ( { } , function ( err , dirPath ) {
0 commit comments