(t *testing.T)
| 147 | } |
| 148 | |
| 149 | func TestRetry_MarkBlockCompacted(t *testing.T) { |
| 150 | var reqCounts sync.Map |
| 151 | |
| 152 | server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 153 | switch r.URL.Path { |
| 154 | case "/b/blerg": |
| 155 | _, _ = w.Write([]byte(`{}`)) |
| 156 | default: |
| 157 | val, _ := reqCounts.LoadOrStore(r.URL.Path, &atomic.Int32{}) |
| 158 | if atomicCounter, ok := val.(*atomic.Int32); ok { |
| 159 | atomicCounter.Add(1) |
| 160 | } |
| 161 | |
| 162 | // First two requests fail, third succeeds for each path. |
| 163 | if val.(*atomic.Int32).Load() <= 2 { |
| 164 | w.WriteHeader(503) |
| 165 | return |
| 166 | } |
| 167 | _, _ = w.Write([]byte(`{"done": true}`)) |
| 168 | } |
| 169 | })) |
| 170 | server.StartTLS() |
| 171 | t.Cleanup(server.Close) |
| 172 | |
| 173 | _, _, c, err := New(&Config{ |
| 174 | BucketName: "blerg", |
| 175 | Insecure: true, |
| 176 | Endpoint: server.URL, |
| 177 | MaxRetries: 3, |
| 178 | }) |
| 179 | require.NoError(t, err) |
| 180 | |
| 181 | id, err := uuid.NewUUID() |
| 182 | require.NoError(t, err) |
| 183 | |
| 184 | require.NoError(t, c.MarkBlockCompacted(id, "tenant")) |
| 185 | |
| 186 | reqCounts.Range(func(key, value any) bool { |
| 187 | urlPath := key.(string) |
| 188 | require.Equal(t, int32(3), value.(*atomic.Int32).Load(), "should attempt 3 times for %s", urlPath) |
| 189 | return true |
| 190 | }) |
| 191 | } |
| 192 | |
| 193 | func TestRetry_ClearBlock(t *testing.T) { |
| 194 | var reqCounts sync.Map |
nothing calls this directly
no test coverage detected