retry_test
API
retry_test
packageAPI reference for the retry_test
package.
F
function
TestDoSucceedsAfterRetry
Parameters
t
pkg/retry/retry_test.go:11-26
func TestDoSucceedsAfterRetry(t *testing.T)
{
attempts := 0
err := retrypkg.Do(context.Background(), func() error {
attempts++
if attempts < 2 {
return errors.New("fail")
}
return nil
}, 3)
if err != nil {
t.Fatalf("Do() error = %v", err)
}
if attempts != 2 {
t.Fatalf("Do() attempts = %d, want %d", attempts, 2)
}
}
F
function
TestDoExhaustsAttempts
Parameters
t
pkg/retry/retry_test.go:28-33
func TestDoExhaustsAttempts(t *testing.T)
{
err := retrypkg.Do(context.Background(), func() error { return errors.New("x") }, 2)
if err == nil {
t.Fatalf("Do() error = nil, want non-nil")
}
}
F
function
TestDoDefaultsToThreeAttempts
Parameters
t
pkg/retry/retry_test.go:35-45
func TestDoDefaultsToThreeAttempts(t *testing.T)
{
attempts := 0
_ = retrypkg.Do(context.Background(), func() error {
attempts++
return errors.New("still failing")
}, 0)
if attempts != 3 {
t.Fatalf("Do() attempts = %d, want %d", attempts, 3)
}
}
F
function
TestDoHonorsContextCancellation
Parameters
t
pkg/retry/retry_test.go:47-58
func TestDoHonorsContextCancellation(t *testing.T)
{
ctx, cancel := context.WithCancel(context.Background())
cancel()
err := retrypkg.Do(ctx, func() error {
t.Fatalf("Do() should not execute function when context is already canceled")
return nil
}, 3)
if !errors.Is(err, context.Canceled) {
t.Fatalf("Do() error = %v, want context.Canceled", err)
}
}