2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 12:55:18 +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
MinimalData: true,
// wait for removals for at least 20s
WaitForDelayedRemoval: 20 * time.Second,
// wait for removals for at least 60s
WaitForDelayedRemoval: 60 * time.Second,
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) {

View File

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