11import { describe , expect , test } from "vitest" ;
22import { ConsoleInterceptor } from "../src/v3/consoleInterceptor.js" ;
33import {
4+ RetryOptions ,
45 RunFnParams ,
56 ServerBackgroundWorker ,
67 TaskMetadataWithFunctions ,
@@ -784,6 +785,48 @@ describe("TaskExecutor", () => {
784785 expect ( ( result as any ) . result . retry . delay ) . toBeLessThan ( 30100 ) ;
785786 } ) ;
786787
788+ test ( "should use the default retry settings if no catch error hook is provided" , async ( ) => {
789+ const expectedError = new Error ( "Task failed intentionally" ) ;
790+
791+ const task = {
792+ id : "test-task" ,
793+ fns : {
794+ run : async ( payload : any , params : RunFnParams < any > ) => {
795+ throw expectedError ;
796+ } ,
797+ } ,
798+ } ;
799+
800+ const result = await executeTask ( task , { test : "data" } , undefined , {
801+ maxAttempts : 3 ,
802+ minTimeoutInMs : 1000 ,
803+ maxTimeoutInMs : 5000 ,
804+ factor : 2 ,
805+ } ) ;
806+
807+ // Verify the final result contains the specific retry timing
808+ expect ( result ) . toEqual ( {
809+ result : {
810+ ok : false ,
811+ id : "test-run-id" ,
812+ error : {
813+ type : "BUILT_IN_ERROR" ,
814+ message : "Task failed intentionally" ,
815+ name : "Error" ,
816+ stackTrace : expect . any ( String ) ,
817+ } ,
818+ retry : {
819+ timestamp : expect . any ( Number ) ,
820+ delay : expect . any ( Number ) ,
821+ } ,
822+ skippedRetrying : false ,
823+ } ,
824+ } ) ;
825+
826+ expect ( ( result as any ) . result . retry . delay ) . toBeGreaterThan ( 1000 ) ;
827+ expect ( ( result as any ) . result . retry . delay ) . toBeLessThan ( 3000 ) ;
828+ } ) ;
829+
787830 test ( "should execute middleware hooks in correct order around other hooks" , async ( ) => {
788831 const executionOrder : string [ ] = [ ] ;
789832
@@ -1623,7 +1666,12 @@ describe("TaskExecutor", () => {
16231666 } ) ;
16241667} ) ;
16251668
1626- function executeTask ( task : TaskMetadataWithFunctions , payload : any , signal ?: AbortSignal ) {
1669+ function executeTask (
1670+ task : TaskMetadataWithFunctions ,
1671+ payload : any ,
1672+ signal ?: AbortSignal ,
1673+ retrySettings ?: RetryOptions
1674+ ) {
16271675 const tracingSDK = new TracingSDK ( {
16281676 url : "http://localhost:4318" ,
16291677 } ) ;
@@ -1643,7 +1691,7 @@ function executeTask(task: TaskMetadataWithFunctions, payload: any, signal?: Abo
16431691 consoleInterceptor,
16441692 retries : {
16451693 enabledInDev : false ,
1646- default : {
1694+ default : retrySettings ?? {
16471695 maxAttempts : 1 ,
16481696 } ,
16491697 } ,
0 commit comments