2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

swift: Increase backend test delay for removed file

This commit is contained in:
Alexander Neumann 2017-07-21 18:00:17 +02:00
parent 0cb4104aa7
commit 46fa45942e
2 changed files with 32 additions and 22 deletions

View File

@ -20,8 +20,8 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
// do not use excessive data // do not use excessive data
MinimalData: true, MinimalData: true,
// wait for removals for at least 20s // wait for removals for at least 60s
WaitForDelayedRemoval: 20 * time.Second, WaitForDelayedRemoval: 60 * time.Second,
// NewConfig returns a config for a new temporary backend that will be used in tests. // NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) { NewConfig: func() (interface{}, error) {

View File

@ -330,7 +330,7 @@ func (s *Suite) TestSave(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = delayedRemove(t, b, h, s.WaitForDelayedRemoval) err = delayedRemove(t, b, s.WaitForDelayedRemoval, h)
if err != nil { if err != nil {
t.Fatalf("error removing item: %+v", err) t.Fatalf("error removing item: %+v", err)
} }
@ -435,18 +435,24 @@ func testLoad(b restic.Backend, h restic.Handle, length int, offset int64) error
return err return err
} }
func delayedRemove(t testing.TB, be restic.Backend, h restic.Handle, maxwait time.Duration) error { func delayedRemove(t testing.TB, be restic.Backend, maxwait time.Duration, handles ...restic.Handle) error {
// Some backend (swift, I'm looking at you) may implement delayed // Some backend (swift, I'm looking at you) may implement delayed
// removal of data. Let's wait a bit if this happens. // removal of data. Let's wait a bit if this happens.
for _, h := range handles {
err := be.Remove(context.TODO(), h) err := be.Remove(context.TODO(), h)
if err != nil { if err != nil {
return err return err
} }
}
for _, h := range handles {
start := time.Now() start := time.Now()
attempt := 0 attempt := 0
var found bool
var err error
for time.Since(start) <= maxwait { for time.Since(start) <= maxwait {
found, err := be.Test(context.TODO(), h) found, err = be.Test(context.TODO(), h)
if err != nil { if err != nil {
return err return err
} }
@ -455,10 +461,15 @@ func delayedRemove(t testing.TB, be restic.Backend, h restic.Handle, maxwait tim
break break
} }
time.Sleep(500 * time.Millisecond) time.Sleep(2 * time.Second)
attempt++ attempt++
} }
if found {
t.Fatalf("removed blob %v still present after %v (%d attempts)", h, time.Since(start), attempt)
}
}
return nil return nil
} }
@ -552,7 +563,7 @@ func (s *Suite) TestBackend(t *testing.T) {
test.Assert(t, err != nil, "expected error for %v, got %v", h, err) test.Assert(t, err != nil, "expected error for %v, got %v", h, err)
// remove and recreate // remove and recreate
err = delayedRemove(t, b, h, s.WaitForDelayedRemoval) err = delayedRemove(t, b, s.WaitForDelayedRemoval, h)
test.OK(t, err) test.OK(t, err)
// test that the blob is gone // test that the blob is gone
@ -587,6 +598,7 @@ func (s *Suite) TestBackend(t *testing.T) {
// remove content if requested // remove content if requested
if test.TestCleanupTempDirs { if test.TestCleanupTempDirs {
var handles []restic.Handle
for _, ts := range testStrings { for _, ts := range testStrings {
id, err := restic.ParseID(ts.id) id, err := restic.ParseID(ts.id)
test.OK(t, err) test.OK(t, err)
@ -597,12 +609,10 @@ func (s *Suite) TestBackend(t *testing.T) {
test.OK(t, err) test.OK(t, err)
test.Assert(t, found, fmt.Sprintf("id %q not found", id)) test.Assert(t, found, fmt.Sprintf("id %q not found", id))
test.OK(t, delayedRemove(t, b, h, s.WaitForDelayedRemoval)) handles = append(handles, h)
found, err = b.Test(context.TODO(), h)
test.OK(t, err)
test.Assert(t, !found, fmt.Sprintf("id %q found after removal", id))
} }
test.OK(t, delayedRemove(t, b, s.WaitForDelayedRemoval, handles...))
} }
} }
} }