@@ -517,57 +517,38 @@ test.skip('del removes both key and its ttl meta data (custom ttlEncoding)', fun
517517 } , { valueEncoding : 'utf8' } )
518518} , { keyEncoding : 'utf8' , valueEncoding : 'json' , ttlEncoding : bytewise } )
519519
520- // TODO: rewrite to be less sensitive and more a unit test
521- // eslint-disable-next-line no-unused-vars
522- function wrappedTest ( ) {
523- var intervals = 0
524- var _setInterval = global . setInterval
525- var _clearInterval = global . clearInterval
526-
527- global . setInterval = function ( ) {
528- intervals ++
529- return _setInterval . apply ( global , arguments )
530- }
531-
532- global . clearInterval = function ( ) {
533- intervals --
534- return _clearInterval . apply ( global , arguments )
535- }
520+ {
521+ let intervals = 0
536522
537- test ( 'test stop() method stops interval and doesn\'t hold process up ' , function ( t , db ) {
523+ test ( 'test stop() method stops interval' , function ( t , db ) {
538524 t . equals ( intervals , 1 , '1 interval timer' )
539- db . put ( 'foo' , 'bar1' , { ttl : 25 } )
540525
541- setTimeout ( function ( ) {
542- db . get ( 'foo' , function ( err , value ) {
543- t . notOk ( err , 'no error' )
544- t . equal ( 'bar1' , value )
545- } )
546- } , 40 )
526+ db . put ( 'foo' , 'bar1' , { ttl : 25 } , function ( err ) {
527+ t . ifError ( err , 'no put error' )
547528
548- setTimeout ( function ( ) {
549- db . get ( 'foo' , function ( err , value ) {
550- t . ok ( err && err . notFound , 'not found error' )
551- t . notOk ( value , 'no value' )
552- } )
553- } , 80 )
529+ waitForSweep ( db , function ( ) {
530+ db . get ( 'foo' , function ( err ) {
531+ t . ok ( err && err . notFound , 'not found error' )
554532
555- setTimeout ( function ( ) {
556- db . stop ( function ( ) {
557- db . _ttl . close ( function ( ) {
558- global . setInterval = _setInterval
559- global . clearInterval = _clearInterval
560- t . equals ( 0 , intervals , 'all interval timers cleared' )
561- t . end ( )
533+ db . stop ( function ( ) {
534+ t . equals ( 0 , intervals , 'all interval timers cleared' )
535+ db . _ttl . close ( t . end . bind ( t ) )
536+ } )
562537 } )
563538 } )
564- } , 120 )
539+ } )
540+ } , {
541+ setInterval : function ( ) {
542+ intervals ++
543+ return setInterval . apply ( null , arguments )
544+ } ,
545+ clearInterval : function ( ) {
546+ intervals --
547+ return clearInterval . apply ( null , arguments )
548+ }
565549 } )
566550}
567551
568- // TODO: restore
569- // wrappedTest()
570-
571552// TODO: rewrite to be less sensitive and more a unit test
572553function put ( timeout , opts ) {
573554 return function ( t , db ) {
0 commit comments