From e1f722d2666fd36df6a5781602da5b26abe7ff12 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 14 Feb 2020 23:16:13 +0100 Subject: [PATCH] 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. --- internal/archiver/archiver_test.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/internal/archiver/archiver_test.go b/internal/archiver/archiver_test.go index ce38f52e2..40514500a 100644 --- a/internal/archiver/archiver_test.go +++ b/internal/archiver/archiver_test.go @@ -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 {