archiver: Fix flaky TestArchiverAbortEarlyOnError

Each of the random test files was split into the same five blobs. The
test fails once the fifth blob is passed on to `SaveBlob`. That is for
certain interleavings of goroutine execution it would be possible for
the test to trigger the testErr just after storing the first file.

The fixed test uses a different file content for each of the nine files
and fails after writing the fourth blob. The file content is also small
enough to ensure that for each file only a single blob is saved. This
guarantees that the test cannot fail before reading the first four
files. FileReadConcurrency = 2 allows up to two files queued for
processing. Therefore the test can at most open the sixth file before it
has to save the fourth file / blob which triggers the testErr.
This commit is contained in:
Michael Eischer 2020-02-14 23:16:13 +01:00
parent 2d47381b1d
commit e1f722d266
1 changed files with 18 additions and 12 deletions

View File

@ -1856,7 +1856,7 @@ func TestArchiverAbortEarlyOnError(t *testing.T) {
var tests = []struct {
src TestDir
wantOpen map[string]uint
failAfter uint // error after so many files have been saved to the repo
failAfter uint // error after so many blobs have been saved to the repo
err error
}{
{
@ -1876,26 +1876,29 @@ func TestArchiverAbortEarlyOnError(t *testing.T) {
{
src: TestDir{
"dir": TestDir{
"file1": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file2": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file3": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file4": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file5": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file6": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file7": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file8": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file9": TestFile{Content: string(restictest.Random(3, 4*1024*1024))},
"file1": TestFile{Content: string(restictest.Random(1, 1024))},
"file2": TestFile{Content: string(restictest.Random(2, 1024))},
"file3": TestFile{Content: string(restictest.Random(3, 1024))},
"file4": TestFile{Content: string(restictest.Random(4, 1024))},
"file5": TestFile{Content: string(restictest.Random(5, 1024))},
"file6": TestFile{Content: string(restictest.Random(6, 1024))},
"file7": TestFile{Content: string(restictest.Random(7, 1024))},
"file8": TestFile{Content: string(restictest.Random(8, 1024))},
"file9": TestFile{Content: string(restictest.Random(9, 1024))},
},
},
wantOpen: map[string]uint{
filepath.FromSlash("dir/file1"): 1,
filepath.FromSlash("dir/file2"): 1,
filepath.FromSlash("dir/file3"): 1,
filepath.FromSlash("dir/file4"): 1,
filepath.FromSlash("dir/file7"): 0,
filepath.FromSlash("dir/file8"): 0,
filepath.FromSlash("dir/file9"): 0,
},
failAfter: 5,
// fails four to six files were opened as the FileReadConcurrency allows for
// two queued files
failAfter: 4,
err: testErr,
},
}
@ -1926,7 +1929,10 @@ func TestArchiverAbortEarlyOnError(t *testing.T) {
err: test.err,
}
arch := New(testRepo, testFS, Options{})
// at most two files may be queued
arch := New(testRepo, testFS, Options{
FileReadConcurrency: 2,
})
_, _, err := arch.Snapshot(ctx, []string{"."}, SnapshotOptions{Time: time.Now()})
if errors.Cause(err) != test.err {