X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c447d4a79f653bbf2c172a0a715d30db896a4a32..da3017f2d1c4a6838255814a96cbb66acde14d0a:/services/keepstore/volume_unix_test.go diff --git a/services/keepstore/volume_unix_test.go b/services/keepstore/volume_unix_test.go index 35cf457d8f..0775e89ed2 100644 --- a/services/keepstore/volume_unix_test.go +++ b/services/keepstore/volume_unix_test.go @@ -16,10 +16,10 @@ import ( type TestableUnixVolume struct { UnixVolume - t *testing.T + t TB } -func NewTestableUnixVolume(t *testing.T, serialize bool, readonly bool) *TestableUnixVolume { +func NewTestableUnixVolume(t TB, serialize bool, readonly bool) *TestableUnixVolume { d, err := ioutil.TempDir("", "volume_test") if err != nil { t.Fatal(err) @@ -66,25 +66,41 @@ func (v *TestableUnixVolume) Teardown() { // serialize = false; readonly = false func TestUnixVolumeWithGenericTests(t *testing.T) { - DoGenericVolumeTests(t, func(t *testing.T) TestableVolume { + DoGenericVolumeTests(t, func(t TB) TestableVolume { return NewTestableUnixVolume(t, false, false) }) } // serialize = false; readonly = true func TestUnixVolumeWithGenericTestsReadOnly(t *testing.T) { - DoGenericVolumeTests(t, func(t *testing.T) TestableVolume { + DoGenericVolumeTests(t, func(t TB) TestableVolume { return NewTestableUnixVolume(t, false, true) }) } // serialize = true; readonly = false func TestUnixVolumeWithGenericTestsSerialized(t *testing.T) { - DoGenericVolumeTests(t, func(t *testing.T) TestableVolume { + DoGenericVolumeTests(t, func(t TB) TestableVolume { return NewTestableUnixVolume(t, true, false) }) } +// serialize = false; readonly = false +func TestUnixVolumeHandlersWithGenericVolumeTests(t *testing.T) { + DoHandlersWithGenericVolumeTests(t, func(t TB) (*RRVolumeManager, []TestableVolume) { + vols := make([]Volume, 2) + testableUnixVols := make([]TestableVolume, 2) + + for i := range vols { + v := NewTestableUnixVolume(t, false, false) + vols[i] = v + testableUnixVols[i] = v + } + + return MakeRRVolumeManager(vols), testableUnixVols + }) +} + func TestGetNotFound(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() @@ -150,7 +166,7 @@ func TestUnixVolumeReadonly(t *testing.T) { t.Errorf("got err %v, expected MethodDisabledError", err) } - err = v.Delete(TestHash) + err = v.Trash(TestHash) if err != MethodDisabledError { t.Errorf("got err %v, expected MethodDisabledError", err) } @@ -291,65 +307,6 @@ func TestUnixVolumeCompare(t *testing.T) { } } -// Put an EmptyBlock and get and compare for EmptyHash -// With #7329 unresolved, Compare falls in infinite loop -func TestGetAndCompareEmptyBlock(t *testing.T) { - v := NewTestableUnixVolume(t, false, false) - defer v.Teardown() - - v.Put(EmptyHash, EmptyBlock) - - buf, err := v.Get(EmptyHash) - if err != nil { - t.Errorf("Error during Get for %q: %s", EmptyHash, err) - } - - err = v.Compare(EmptyHash, buf) - if err != nil { - t.Errorf("Error during Compare for %q: %s", EmptyHash, err) - } -} - -// Put baddata for EmptyHash. Get will succeed, but Compare will raise DiskHashError -func TestGetAndCompareEmptyHashWithDiskHashError(t *testing.T) { - v := NewTestableUnixVolume(t, false, false) - defer v.Teardown() - - v.PutRaw(EmptyHash, []byte("baddata")) - - _, err := v.Get(EmptyHash) - if err != nil { - t.Errorf("Unexpected error after PutRaw EmptyHash with baddata") - } - - err = v.Compare(EmptyHash, EmptyBlock) - if err != DiskHashError { - t.Errorf("Expected DiskHashError when comparing EmptyHash with bad data. Got %s", err) - } -} - -// Get non existing empty block; should fail with file not found error. -func TestGetEmptyBlockNonExisting(t *testing.T) { - v := NewTestableUnixVolume(t, false, false) - defer v.Teardown() - - buf, err := v.Get(EmptyHash) - if err == nil { - t.Errorf("Get non existing empty hash should have failed, instead got %q", buf) - } -} - -// Compare non existing empty hash should fail with file not found error. -func TestCompareEmptyHashNonExisting(t *testing.T) { - v := NewTestableUnixVolume(t, false, false) - defer v.Teardown() - - err := v.Compare(EmptyHash, EmptyBlock) - if err == nil { - t.Errorf("Expected error no such file. But got no error.") - } -} - // TODO(twp): show that the underlying Read/Write operations executed // serially and not concurrently. The easiest way to do this is // probably to activate verbose or debug logging, capture log output