@@ -35,7 +35,7 @@ func TestDoWithDataAllFailed(t *testing.T) {
35
35
assert .Len (t , err , 10 )
36
36
fmt .Println (err .Error ())
37
37
assert .Equal (t , expectedErrorFormat , err .Error (), "retry error format" )
38
- assert .Equal (t , uint (45 ), retrySum , "right count of retry" )
38
+ assert .Equal (t , uint (36 ), retrySum , "right count of retry" )
39
39
}
40
40
41
41
func TestDoFirstOk (t * testing.T ) {
@@ -632,6 +632,28 @@ func BenchmarkDoWithDataNoErrors(b *testing.B) {
632
632
}
633
633
}
634
634
635
+ func TestOnRetryNotCalledOnLastAttempt (t * testing.T ) {
636
+ callCount := 0
637
+ onRetryCalls := make ([]uint , 0 )
638
+
639
+ err := Do (
640
+ func () error {
641
+ callCount ++
642
+ return errors .New ("test error" )
643
+ },
644
+ Attempts (3 ),
645
+ OnRetry (func (n uint , err error ) {
646
+ onRetryCalls = append (onRetryCalls , n )
647
+ }),
648
+ Delay (time .Nanosecond ),
649
+ )
650
+
651
+ assert .Error (t , err )
652
+ assert .Equal (t , 3 , callCount , "function should be called 3 times" )
653
+ assert .Equal (t , []uint {0 , 1 }, onRetryCalls , "onRetry should only be called for first 2 attempts, not the final one" )
654
+ assert .Len (t , onRetryCalls , 2 , "onRetry should be called exactly 2 times (not on last attempt)" )
655
+ }
656
+
635
657
func TestIsRecoverable (t * testing.T ) {
636
658
err := errors .New ("err" )
637
659
assert .True (t , IsRecoverable (err ))
0 commit comments