2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 02:48:55 +00:00

Merge pull request #1244 from restic/fix-swift-backend-tests

Ignore "not exist" errors for swift backend tests
This commit is contained in:
Alexander Neumann 2017-09-16 14:54:32 +02:00
commit c784a15aaa
3 changed files with 29 additions and 7 deletions

View File

@ -20,8 +20,21 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
// do not use excessive data
MinimalData: true,
// wait for removals for at least 60s
WaitForDelayedRemoval: 60 * time.Second,
// wait for removals for at least 5m
WaitForDelayedRemoval: 5 * time.Minute,
ErrorHandler: func(t testing.TB, be restic.Backend, err error) error {
if err == nil {
return nil
}
if be.IsNotExist(err) {
t.Logf("swift: ignoring error %v", err)
return nil
}
return err
},
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) {

View File

@ -34,6 +34,9 @@ type Suite struct {
// suite to wait for this amount of time until a file that was removed
// really disappeared.
WaitForDelayedRemoval time.Duration
// ErrorHandler allows ignoring certain errors.
ErrorHandler func(testing.TB, restic.Backend, error) error
}
// RunTests executes all defined tests as subtests of t.

View File

@ -331,7 +331,7 @@ func (s *Suite) TestSave(t *testing.T) {
t.Fatal(err)
}
err = delayedRemove(t, b, s.WaitForDelayedRemoval, h)
err = s.delayedRemove(t, b, h)
if err != nil {
t.Fatalf("error removing item: %+v", err)
}
@ -436,12 +436,15 @@ func testLoad(b restic.Backend, h restic.Handle, length int, offset int64) error
return err
}
func delayedRemove(t testing.TB, be restic.Backend, maxwait time.Duration, handles ...restic.Handle) error {
func (s *Suite) delayedRemove(t testing.TB, be restic.Backend, handles ...restic.Handle) error {
// Some backend (swift, I'm looking at you) may implement delayed
// removal of data. Let's wait a bit if this happens.
for _, h := range handles {
err := be.Remove(context.TODO(), h)
if s.ErrorHandler != nil {
err = s.ErrorHandler(t, be, err)
}
if err != nil {
return err
}
@ -452,8 +455,11 @@ func delayedRemove(t testing.TB, be restic.Backend, maxwait time.Duration, handl
attempt := 0
var found bool
var err error
for time.Since(start) <= maxwait {
for time.Since(start) <= s.WaitForDelayedRemoval {
found, err = be.Test(context.TODO(), h)
if s.ErrorHandler != nil {
err = s.ErrorHandler(t, be, err)
}
if err != nil {
return err
}
@ -564,7 +570,7 @@ func (s *Suite) TestBackend(t *testing.T) {
test.Assert(t, err != nil, "expected error for %v, got %v", h, err)
// remove and recreate
err = delayedRemove(t, b, s.WaitForDelayedRemoval, h)
err = s.delayedRemove(t, b, h)
test.OK(t, err)
// test that the blob is gone
@ -613,7 +619,7 @@ func (s *Suite) TestBackend(t *testing.T) {
handles = append(handles, h)
}
test.OK(t, delayedRemove(t, b, s.WaitForDelayedRemoval, handles...))
test.OK(t, s.delayedRemove(t, b, handles...))
}
}
}