(t *testing.T)
| 256 | } |
| 257 | |
| 258 | func TestBackendLoadRetry(t *testing.T) { |
| 259 | data := test.Random(23, 1024) |
| 260 | limit := 100 |
| 261 | attempt := 0 |
| 262 | |
| 263 | be := mock.NewBackend() |
| 264 | be.OpenReaderFn = func(ctx context.Context, h backend.Handle, length int, offset int64) (io.ReadCloser, error) { |
| 265 | // returns failing reader on first invocation, good reader on subsequent invocations |
| 266 | attempt++ |
| 267 | if attempt > 1 { |
| 268 | return closingReader{rd: bytes.NewReader(data)}, nil |
| 269 | } |
| 270 | return failingReader{data: data, limit: limit}, nil |
| 271 | } |
| 272 | |
| 273 | TestFastRetries(t) |
| 274 | retryBackend := New(be, 10, nil, nil) |
| 275 | |
| 276 | var buf []byte |
| 277 | err := retryBackend.Load(context.TODO(), backend.Handle{}, 0, 0, func(rd io.Reader) (err error) { |
| 278 | buf, err = io.ReadAll(rd) |
| 279 | return err |
| 280 | }) |
| 281 | test.OK(t, err) |
| 282 | test.Equals(t, data, buf) |
| 283 | test.Equals(t, 2, attempt) |
| 284 | } |
| 285 | |
| 286 | func testBackendLoadNotExists(t *testing.T, hasFlakyErrors bool) { |
| 287 | // load should not retry if the error matches IsNotExist |
nothing calls this directly
no test coverage detected