forked from TrueCloudLab/restic
test retry on repo opening
This commit is contained in:
parent
58dc4a6892
commit
b5bc76cdc7
1 changed files with 44 additions and 0 deletions
|
@ -177,3 +177,47 @@ func TestFindListOnce(t *testing.T) {
|
|||
// the snapshots can only be listed once, if both lists match then the there has been only a single List() call
|
||||
rtest.Equals(t, thirdSnapshot, snapshotIDs)
|
||||
}
|
||||
|
||||
type failConfigOnceBackend struct {
|
||||
backend.Backend
|
||||
failedOnce bool
|
||||
}
|
||||
|
||||
func (be *failConfigOnceBackend) Load(ctx context.Context, h backend.Handle,
|
||||
length int, offset int64, fn func(rd io.Reader) error) error {
|
||||
|
||||
if !be.failedOnce && h.Type == restic.ConfigFile {
|
||||
be.failedOnce = true
|
||||
return fmt.Errorf("oops")
|
||||
}
|
||||
return be.Backend.Load(ctx, h, length, offset, fn)
|
||||
}
|
||||
|
||||
func (be *failConfigOnceBackend) Stat(ctx context.Context, h backend.Handle) (backend.FileInfo, error) {
|
||||
if !be.failedOnce && h.Type == restic.ConfigFile {
|
||||
be.failedOnce = true
|
||||
return backend.FileInfo{}, fmt.Errorf("oops")
|
||||
}
|
||||
return be.Backend.Stat(ctx, h)
|
||||
}
|
||||
|
||||
func TestBackendRetryConfig(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
||||
var wrappedBackend *failConfigOnceBackend
|
||||
// cause config loading to fail once
|
||||
env.gopts.backendInnerTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
wrappedBackend = &failConfigOnceBackend{Backend: r}
|
||||
return wrappedBackend, nil
|
||||
}
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
rtest.Assert(t, wrappedBackend != nil, "backend not wrapped on init")
|
||||
rtest.Assert(t, wrappedBackend != nil && wrappedBackend.failedOnce, "config loading was not retried on init")
|
||||
wrappedBackend = nil
|
||||
|
||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9")}, BackupOptions{}, env.gopts)
|
||||
rtest.Assert(t, wrappedBackend != nil, "backend not wrapped on backup")
|
||||
rtest.Assert(t, wrappedBackend != nil && wrappedBackend.failedOnce, "config loading was not retried on init")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue