summaryrefslogtreecommitdiffstatshomepage
path: root/internal/test/test_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/test/test_test.go')
-rw-r--r--internal/test/test_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/test/test_test.go b/internal/test/test_test.go
new file mode 100644
index 000000000..264398c19
--- /dev/null
+++ b/internal/test/test_test.go
@@ -0,0 +1,42 @@
+package test
+
+import (
+ "testing"
+ "time"
+)
+
+func Test_SucceedsImmediately(t *testing.T) {
+ var attempts int
+
+ f := NewFlaky(t, &FlakyOptions{
+ MaxAttempts: 3,
+ InitialBackoff: 10 * time.Millisecond,
+ })
+
+ f.Run(func(t testing.TB) {
+ attempts++
+ if attempts > 1 {
+ t.Fatalf("should not retry on success")
+ }
+ })
+}
+
+func Test_EventualSuccess(t *testing.T) {
+ var attempts int
+
+ f := NewFlaky(t, &FlakyOptions{
+ MaxAttempts: 5,
+ InitialBackoff: 10 * time.Millisecond,
+ })
+
+ f.Run(func(t testing.TB) {
+ attempts++
+ if attempts < 3 {
+ t.Fatalf("intentional failure")
+ }
+ })
+
+ if attempts != 3 {
+ t.Fatalf("expected 3 attempts, got %d", attempts)
+ }
+}