@@ -220,7 +220,18 @@ describe("EventProcessor - processEvents", () => {
220220 ) ;
221221
222222 expect ( opts . backoff ) . toHaveBeenCalledOnce ( ) ;
223- expect ( opts . backoff ) . toHaveBeenCalledWith ( 5 ) ; // evt.errors + 1
223+ expect ( opts . backoff ) . toHaveBeenCalledWith (
224+ expect . objectContaining ( {
225+ attempt : 5 ,
226+ error : err ,
227+ errors : expect . arrayContaining ( [ err ] ) ,
228+ event : expect . objectContaining ( {
229+ id : "1" ,
230+ errors : 5 ,
231+ } ) ,
232+ maxErrors : opts . maxErrors ,
233+ } ) ,
234+ ) ; // evt.errors + 1
224235
225236 expect ( mockTxClient . updateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
226237 expect ( mockTxClient . updateEvent ) . toHaveBeenCalledWith ( {
@@ -525,7 +536,12 @@ describe("EventProcessor - processEvents", () => {
525536
526537 // Backoff is called even when reaching maxErrors (then backoff_until is nulled)
527538 expect ( opts . backoff ) . toHaveBeenCalledOnce ( ) ;
528- expect ( opts . backoff ) . toHaveBeenCalledWith ( opts . maxErrors ) ;
539+ expect ( opts . backoff ) . toHaveBeenCalledWith (
540+ expect . objectContaining ( {
541+ attempt : opts . maxErrors ,
542+ maxErrors : opts . maxErrors ,
543+ } ) ,
544+ ) ;
529545
530546 // Should call the maxErrors callback
531547 expect ( opts . onEventMaxErrorsReached ) . toHaveBeenCalledOnce ( ) ;
@@ -623,7 +639,12 @@ describe("EventProcessor - processEvents", () => {
623639 expect ( handlerMap . evtType1 . handler2 ) . toHaveBeenCalledOnce ( ) ;
624640
625641 // Should call backoff even when jumping to maxErrors
626- expect ( opts . backoff ) . toHaveBeenCalledWith ( opts . maxErrors ) ;
642+ expect ( opts . backoff ) . toHaveBeenCalledWith (
643+ expect . objectContaining ( {
644+ attempt : opts . maxErrors ,
645+ maxErrors : opts . maxErrors ,
646+ } ) ,
647+ ) ;
627648
628649 // Should call the maxErrors callback since all remaining handlers are unprocessable
629650 expect ( opts . onEventMaxErrorsReached ) . toHaveBeenCalledOnce ( ) ;
@@ -711,7 +732,13 @@ describe("EventProcessor - processEvents", () => {
711732 expect ( handlerMap . evtType1 . handler3 ) . toHaveBeenCalledOnce ( ) ;
712733
713734 // Should call backoff normally since handler3 has retryable error
714- expect ( opts . backoff ) . toHaveBeenCalledWith ( 1 ) ;
735+ expect ( opts . backoff ) . toHaveBeenCalledWith (
736+ expect . objectContaining ( {
737+ attempt : 1 ,
738+ error : retryableError ,
739+ errors : expect . arrayContaining ( [ retryableError ] ) ,
740+ } ) ,
741+ ) ;
715742
716743 // Should NOT call the maxErrors callback since errors < maxErrors
717744 expect ( opts . onEventMaxErrorsReached ) . not . toHaveBeenCalled ( ) ;
@@ -888,7 +915,12 @@ describe("EventProcessor - processEvents", () => {
888915 expect ( handlerMap . evtType1 . handler3 ) . toHaveBeenCalledOnce ( ) ;
889916
890917 // Default backoff should also be called
891- expect ( opts . backoff ) . toHaveBeenCalledWith ( 1 ) ;
918+ expect ( opts . backoff ) . toHaveBeenCalledWith (
919+ expect . objectContaining ( {
920+ attempt : 1 ,
921+ maxErrors : opts . maxErrors ,
922+ } ) ,
923+ ) ;
892924
893925 // The latest backoff (backoff2 = 20 seconds) should be used
894926 expect ( mockTxClient . updateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -950,7 +982,13 @@ describe("EventProcessor - processEvents", () => {
950982 await processor . stop ( ) ;
951983
952984 expect ( mockClient . transaction ) . toHaveBeenCalledTimes ( 1 ) ;
953- expect ( opts . backoff ) . toHaveBeenCalledWith ( 1 ) ;
985+ expect ( opts . backoff ) . toHaveBeenCalledWith (
986+ expect . objectContaining ( {
987+ attempt : 1 ,
988+ error,
989+ errors : expect . arrayContaining ( [ error ] ) ,
990+ } ) ,
991+ ) ;
954992
955993 // The latest backoff (laterBackoff = 30 seconds) should be used, not the default (5 seconds)
956994 const updateCall = mockTxClient . updateEvent . mock . calls [ 0 ] [ 0 ] ;
@@ -1013,7 +1051,13 @@ describe("EventProcessor - processEvents", () => {
10131051 await processor . stop ( ) ;
10141052
10151053 expect ( mockClient . transaction ) . toHaveBeenCalledTimes ( 1 ) ;
1016- expect ( opts . backoff ) . toHaveBeenCalledWith ( 1 ) ;
1054+ expect ( opts . backoff ) . toHaveBeenCalledWith (
1055+ expect . objectContaining ( {
1056+ attempt : 1 ,
1057+ error,
1058+ errors : expect . arrayContaining ( [ error ] ) ,
1059+ } ) ,
1060+ ) ;
10171061
10181062 // The latest backoff (defaultBackoffTime = 5 seconds) should be used, not the earlier one (2 seconds)
10191063 const updateCall = mockTxClient . updateEvent . mock . calls [ 0 ] [ 0 ] ;
@@ -1026,7 +1070,21 @@ describe("EventProcessor - processEvents", () => {
10261070
10271071describe ( "defaultBackoff" , ( ) => {
10281072 it ( "should calculate a backoff" , ( ) => {
1029- const backoff = defaultBackoff ( 3 ) ;
1073+ const backoff = defaultBackoff ( {
1074+ attempt : 3 ,
1075+ error : new Error ( "test" ) ,
1076+ errors : [ ] ,
1077+ event : {
1078+ id : "event-1" ,
1079+ type : "evtType1" ,
1080+ timestamp : now ,
1081+ data : { } ,
1082+ correlation_id : "abc123" ,
1083+ handler_results : { } ,
1084+ errors : 3 ,
1085+ } ,
1086+ maxErrors : 5 ,
1087+ } ) ;
10301088 const actual = backoff . getTime ( ) ;
10311089 const expected = Date . now ( ) + 1000 * 2 ** 3 ;
10321090 const diff = Math . abs ( actual - expected ) ;
@@ -1036,7 +1094,21 @@ describe("defaultBackoff", () => {
10361094
10371095 it ( "should cap backoff at maxDelayMs for large error counts" , ( ) => {
10381096 const maxDelayMs = 1000 * 60 ; // 60 seconds
1039- const backoff = defaultBackoff ( 20 ) ; // Large error count that would exceed max
1097+ const backoff = defaultBackoff ( {
1098+ attempt : 20 ,
1099+ error : new Error ( "test" ) ,
1100+ errors : [ ] ,
1101+ event : {
1102+ id : "event-1" ,
1103+ type : "evtType1" ,
1104+ timestamp : now ,
1105+ data : { } ,
1106+ correlation_id : "abc123" ,
1107+ handler_results : { } ,
1108+ errors : 20 ,
1109+ } ,
1110+ maxErrors : 30 ,
1111+ } ) ; // Large error count that would exceed max
10401112 const actual = backoff . getTime ( ) ;
10411113 const expected = Date . now ( ) + maxDelayMs ;
10421114 const diff = Math . abs ( actual - expected ) ;
0 commit comments