Skip to content

Commit

Permalink
Update retry_test.go
Browse files Browse the repository at this point in the history
Adding test with simulated hang
  • Loading branch information
MattCosturos authored Nov 21, 2024
1 parent 02f413f commit 1e1b1a8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ func TestRetry(t *testing.T) {
}
}

func TestRetryHangs(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

f := func() error {
log.Printf("Test Hang")
time.Sleep(10 * time.Second)
return nil
}

err := RetryNotifyWithTimer(f, WithContext(NewConstantBackOff(time.Millisecond), ctx), nil, &testTimer{})
if err == nil {
t.Errorf("error is unexpectedly nil")
}
if !errors.Is(err, context.DeadlineExceeded) {
t.Errorf("unexpected error: %s", err.Error())
}
}

func TestRetryWithData(t *testing.T) {
const successOn = 3
var i = 0
Expand Down

0 comments on commit 1e1b1a8

Please sign in to comment.