@@ -461,6 +461,55 @@ test.group('Worker', () => {
461461 assert . isBelow ( elapsed , 150 , 'Job should be killed before completing' )
462462 } )
463463
464+ test ( 'should apply timeout when timeout is set to 0' , async ( { assert, cleanup } ) => {
465+ assert . plan ( 2 )
466+
467+ class ZeroTimeoutJob extends Job {
468+ static options = { timeout : 0 }
469+
470+ async execute ( ) {
471+ await setTimeout ( 200 )
472+ }
473+
474+ async failed ( error : Error ) {
475+ assert . instanceOf ( error , errors . E_JOB_TIMEOUT )
476+ }
477+ }
478+
479+ const sharedAdapter = memory ( ) ( )
480+
481+ const localConfig = {
482+ default : 'memory' ,
483+ adapters : { memory : ( ) => sharedAdapter } ,
484+ }
485+
486+ Locator . register ( 'ZeroTimeoutJob' , ZeroTimeoutJob )
487+
488+ const worker = new Worker ( localConfig )
489+
490+ cleanup ( async ( ) => {
491+ Locator . clear ( )
492+ await worker . stop ( )
493+ } )
494+
495+ await sharedAdapter . push ( {
496+ id : 'timeout-zero-job' ,
497+ name : 'ZeroTimeoutJob' ,
498+ payload : { } ,
499+ attempts : 0 ,
500+ priority : 0 ,
501+ } )
502+
503+ const startTime = Date . now ( )
504+
505+ await worker . processCycle ( [ 'default' ] ) // started
506+ await worker . processCycle ( [ 'default' ] ) // completed (timeout)
507+
508+ const elapsed = Date . now ( ) - startTime
509+
510+ assert . isBelow ( elapsed , 150 , 'Job should be killed before completing' )
511+ } )
512+
464513 test ( 'should remove timeout abort listener when job completes before timeout' , async ( {
465514 assert,
466515 cleanup,
0 commit comments