8 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
11 func SetupKeepStoreUnixVolumeIntegrationTest(t *testing.T) {
12 os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
14 // Set up Keep unix volumes
15 KeepVM = MakeTestUnixVolumeManager(t, 2)
18 // Start api and keep servers
19 arvadostest.StartAPI()
20 arvadostest.StartKeep()
23 // MakeTestUnixVolumeManager returns a RRVolumeManager
24 // with the specified number of UnixVolumes.
25 var testableUnixVols []*TestableUnixVolume
27 func MakeTestUnixVolumeManager(t *testing.T, numVolumes int) VolumeManager {
28 vols := make([]Volume, numVolumes)
29 testableUnixVols = make([]*TestableUnixVolume, numVolumes)
32 v := NewTestableUnixVolume(t, false, false)
34 testableUnixVols[i] = v
36 return MakeRRVolumeManager(vols)
39 // Put TestBlock and Get it
40 func TestPutTestBlock(t *testing.T) {
41 SetupKeepStoreUnixVolumeIntegrationTest(t)
43 // Check that PutBlock succeeds
44 if err := PutBlock(TestBlock, TestHash); err != nil {
45 t.Fatalf("Error during PutBlock: %s", err)
48 // Check that PutBlock succeeds again even after CompareAndTouch
49 if err := PutBlock(TestBlock, TestHash); err != nil {
50 t.Fatalf("Error during PutBlock: %s", err)
53 // Check that PutBlock stored the data as expected
54 buf, err := GetBlock(TestHash)
56 t.Fatalf("Error during GetBlock for %q: %s", TestHash, err)
57 } else if bytes.Compare(buf, TestBlock) != 0 {
58 t.Errorf("Get response incorrect. Expected %q; found %q", TestBlock, buf)
62 // UnixVolume -> Compare is falling in infinite loop since EOF is not being
63 // returned by reader.Read() for empty block resulting in issue #7329.
64 // Hence invoke PutBlock twice to test that path involving CompareAndTouch
65 func TestPutEmptyBlock(t *testing.T) {
66 SetupKeepStoreUnixVolumeIntegrationTest(t)
68 // Check that PutBlock succeeds
69 if err := PutBlock(EmptyBlock, EmptyHash); err != nil {
70 t.Fatalf("Error during PutBlock: %s", err)
73 // Check that PutBlock succeeds again even after CompareAndTouch
74 // With #7329 unresovled, this falls in infinite loop in UnixVolume -> Compare method
75 if err := PutBlock(EmptyBlock, EmptyHash); err != nil {
76 t.Fatalf("Error during PutBlock: %s", err)
79 // Check that PutBlock stored the data as expected
80 buf, err := GetBlock(EmptyHash)
82 t.Fatalf("Error during GetBlock for %q: %s", EmptyHash, err)
83 } else if bytes.Compare(buf, EmptyBlock) != 0 {
84 t.Errorf("Get response incorrect. Expected %q; found %q", EmptyBlock, buf)
88 // PutRaw EmptyHash with bad data (which bypasses hash check)
89 // and then invoke PutBlock with the correct EmptyBlock.
90 // Put should succeed and next Get should return EmptyBlock
91 func TestPutEmptyBlockDiskHashError(t *testing.T) {
92 SetupKeepStoreUnixVolumeIntegrationTest(t)
94 badEmptyBlock := []byte("verybaddata")
96 // Put bad data for EmptyHash in both volumes
97 testableUnixVols[0].PutRaw(EmptyHash, badEmptyBlock)
98 testableUnixVols[1].PutRaw(EmptyHash, badEmptyBlock)
100 // Check that PutBlock with good data succeeds
101 if err := PutBlock(EmptyBlock, EmptyHash); err != nil {
102 t.Fatalf("Error during PutBlock for %q: %s", EmptyHash, err)
105 // Put succeeded and overwrote the badEmptyBlock in one volume,
106 // and Get should return the EmptyBlock now, ignoring the bad data.
107 buf, err := GetBlock(EmptyHash)
109 t.Fatalf("Error during GetBlock for %q: %s", EmptyHash, err)
110 } else if bytes.Compare(buf, EmptyBlock) != 0 {
111 t.Errorf("Get response incorrect. Expected %q; found %q", TestBlock, buf)