| 92 | } |
| 93 | |
| 94 | func TestDelay(t *testing.T) { |
| 95 | t.Parallel() |
| 96 | |
| 97 | tests := []struct { |
| 98 | attempt int |
| 99 | want time.Duration |
| 100 | }{ |
| 101 | {0, 1 * time.Second}, |
| 102 | {1, 2 * time.Second}, |
| 103 | {2, 4 * time.Second}, |
| 104 | {3, 8 * time.Second}, |
| 105 | {4, 16 * time.Second}, |
| 106 | {5, 32 * time.Second}, |
| 107 | {6, 60 * time.Second}, |
| 108 | {10, 60 * time.Second}, |
| 109 | {100, 60 * time.Second}, |
| 110 | } |
| 111 | |
| 112 | for _, tt := range tests { |
| 113 | t.Run(fmt.Sprintf("Attempt%d", tt.attempt), func(t *testing.T) { |
| 114 | t.Parallel() |
| 115 | got := chatretry.Delay(tt.attempt) |
| 116 | if got != tt.want { |
| 117 | t.Errorf("Delay(%d) = %v, want %v", tt.attempt, got, tt.want) |
| 118 | } |
| 119 | }) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | func TestRetry_SuccessOnFirstTry(t *testing.T) { |
| 124 | t.Parallel() |