Merge pull request #1121 from restic/fix-swift-test

swift: Increase backend test delay for removed file
This commit is contained in:
Alexander Neumann 2017-07-21 20:37:10 +02:00
commit 3830117735
3 changed files with 34 additions and 24 deletions

View File

@ -17,8 +17,8 @@ init:
install: install:
- rmdir c:\go /s /q - rmdir c:\go /s /q
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.8.1.windows-amd64.msi - appveyor DownloadFile https://storage.googleapis.com/golang/go1.8.3.windows-amd64.msi
- msiexec /i go1.8.1.windows-amd64.msi /q - msiexec /i go1.8.3.windows-amd64.msi /q
- go version - go version
- go env - go env
- appveyor DownloadFile http://sourceforge.netcologne.de/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip -FileName tar.zip - appveyor DownloadFile http://sourceforge.netcologne.de/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip -FileName tar.zip

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,28 +435,39 @@ 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.
err := be.Remove(context.TODO(), h)
if err != nil {
return err
}
start := time.Now() for _, h := range handles {
attempt := 0 err := be.Remove(context.TODO(), h)
for time.Since(start) <= maxwait {
found, err := be.Test(context.TODO(), h)
if err != nil { if err != nil {
return err return err
} }
}
if !found { for _, h := range handles {
break 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) if found {
attempt++ 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...))
} }
} }
} }