1package test
2
3import (
4 "testing"
5 "time"
6)
7
8func Test_SucceedsImmediately(t *testing.T) {
9 var attempts int
10
11 f := NewFlaky(t, &FlakyOptions{
12 MaxAttempts: 3,
13 InitialBackoff: 10 * time.Millisecond,
14 })
15
16 f.Run(func(t testing.TB) {
17 attempts++
18 if attempts > 1 {
19 t.Fatalf("should not retry on success")
20 }
21 })
22}
23
24func Test_EventualSuccess(t *testing.T) {
25 var attempts int
26
27 f := NewFlaky(t, &FlakyOptions{
28 MaxAttempts: 5,
29 InitialBackoff: 10 * time.Millisecond,
30 })
31
32 f.Run(func(t testing.TB) {
33 attempts++
34 if attempts < 3 {
35 t.Fatalf("intentional failure")
36 }
37 })
38
39 if attempts != 3 {
40 t.Fatalf("expected 3 attempts, got %d", attempts)
41 }
42}