mirror of
https://github.com/restic/restic.git
synced 2024-12-23 00:07:25 +00:00
backend: Add partial read failure to error backend
This commit is contained in:
parent
8e2ef3f38b
commit
ce4d71d626
1 changed files with 14 additions and 3 deletions
|
@ -3,6 +3,7 @@ package backend
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
// the retry functions.
|
// the retry functions.
|
||||||
type ErrorBackend struct {
|
type ErrorBackend struct {
|
||||||
FailSave float32
|
FailSave float32
|
||||||
|
FailSaveRead float32
|
||||||
FailLoad float32
|
FailLoad float32
|
||||||
FailStat float32
|
FailStat float32
|
||||||
restic.Backend
|
restic.Backend
|
||||||
|
@ -48,6 +50,15 @@ func (be *ErrorBackend) Save(ctx context.Context, h restic.Handle, rd io.Reader)
|
||||||
return errors.Errorf("Save(%v) random error induced", h)
|
return errors.Errorf("Save(%v) random error induced", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if be.fail(be.FailSaveRead) {
|
||||||
|
_, err := io.CopyN(ioutil.Discard, rd, be.r.Int63n(1000))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.Errorf("Save(%v) random error with partial read induced", h)
|
||||||
|
}
|
||||||
|
|
||||||
return be.Backend.Save(ctx, h, rd)
|
return be.Backend.Save(ctx, h, rd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue