@@ -400,41 +400,71 @@ describe('monitoring', function () {
400400 } ) ;
401401 } ) ;
402402
403- context ( 'when it has been < minHeartbeatFrequencyMS since fn() last completed' , function ( ) {
403+ context (
404+ 'when it has been < minHeartbeatFrequencyMS and >= 0 since fn() last completed' ,
405+ function ( ) {
406+ beforeEach ( function ( ) {
407+ executor = new MonitorInterval ( fnSpy , {
408+ minHeartbeatFrequencyMS : 10 ,
409+ heartbeatFrequencyMS : 30
410+ } ) ;
411+
412+ // call fn() once
413+ clock . tick ( 30 ) ;
414+ expect ( fnSpy . calledOnce ) . to . be . true ;
415+
416+ fnSpy . callCount = 0 ;
417+
418+ // advance less than minHeartbeatFrequency
419+ clock . tick ( 5 ) ;
420+
421+ executor . wake ( ) ;
422+ } ) ;
423+
424+ it ( 'reschedules fn() to minHeartbeatFrequencyMS after the last call' , function ( ) {
425+ expect ( fnSpy . callCount ) . to . equal ( 0 ) ;
426+ clock . tick ( 5 ) ;
427+ expect ( fnSpy . calledOnce ) . to . be . true ;
428+ } ) ;
429+
430+ context ( 'when wake() is called more than once' , function ( ) {
431+ it ( 'schedules fn() minHeartbeatFrequencyMS after the last call to fn()' , function ( ) {
432+ executor . wake ( ) ;
433+ executor . wake ( ) ;
434+ executor . wake ( ) ;
435+
436+ expect ( fnSpy . callCount ) . to . equal ( 0 ) ;
437+ clock . tick ( 5 ) ;
438+ expect ( fnSpy . calledOnce ) . to . be . true ;
439+ } ) ;
440+ } ) ;
441+ }
442+ ) ;
443+
444+ context ( 'when it has been <0 since fn() has last executed' , function ( ) {
404445 beforeEach ( function ( ) {
405446 executor = new MonitorInterval ( fnSpy , {
406447 minHeartbeatFrequencyMS : 10 ,
407448 heartbeatFrequencyMS : 30
408449 } ) ;
409450
410- // call fn() once
411- clock . tick ( 30 ) ;
412- expect ( fnSpy . calledOnce ) . to . be . true ;
413-
414- fnSpy . callCount = 0 ;
415-
416- // advance less than minHeartbeatFrequency
417- clock . tick ( 5 ) ;
418-
451+ // negative ticks aren't supported, so manually set execution time
452+ executor . lastExecutionEnded = Infinity ;
419453 executor . wake ( ) ;
420454 } ) ;
421455
422- it ( 'reschedules fn() to minHeartbeatFrequencyMS after the last call' , function ( ) {
423- expect ( fnSpy . callCount ) . to . equal ( 0 ) ;
424- clock . tick ( 5 ) ;
456+ it ( 'executes fn() immediately' , function ( ) {
425457 expect ( fnSpy . calledOnce ) . to . be . true ;
426458 } ) ;
427459
428- context ( 'when wake() is called more than once' , function ( ) {
429- it ( 'schedules fn() minHeartbeatFrequencyMS after the last call to fn()' , function ( ) {
430- executor . wake ( ) ;
431- executor . wake ( ) ;
432- executor . wake ( ) ;
460+ it ( 'reschedules fn() to minHeartbeatFrequency away' , function ( ) {
461+ fnSpy . callCount = 0 ;
433462
434- expect ( fnSpy . callCount ) . to . equal ( 0 ) ;
435- clock . tick ( 5 ) ;
436- expect ( fnSpy . calledOnce ) . to . be . true ;
437- } ) ;
463+ clock . tick ( 29 ) ;
464+ expect ( fnSpy . callCount ) . to . equal ( 0 ) ;
465+
466+ clock . tick ( 1 ) ;
467+ expect ( fnSpy . calledOnce ) . to . be . true ;
438468 } ) ;
439469 } ) ;
440470 } ) ;
0 commit comments