From 1e1b1a89afb1aad189b7c85234ad0431b22da64e Mon Sep 17 00:00:00 2001 From: MattCosturos <48531957+MattCosturos@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:40:40 -0500 Subject: [PATCH] Update retry_test.go Adding test with simulated hang --- retry_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/retry_test.go b/retry_test.go index 0259a95..18b5e3e 100644 --- a/retry_test.go +++ b/retry_test.go @@ -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