MCPcopy
hub / github.com/restic/restic / TestBackendLoadRetry

Function TestBackendLoadRetry

internal/backend/retry/backend_retry_test.go:258–284  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

256}
257
258func 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
286func testBackendLoadNotExists(t *testing.T, hasFlakyErrors bool) {
287 // load should not retry if the error matches IsNotExist

Callers

nothing calls this directly

Calls 7

RandomFunction · 0.92
NewBackendFunction · 0.92
OKFunction · 0.92
EqualsFunction · 0.92
TestFastRetriesFunction · 0.85
NewFunction · 0.70
LoadMethod · 0.65

Tested by

no test coverage detected