X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/46b11ba2ed71e2c074e9e6c8f5b9f7a003e7067f..bc816b50fc16182fef2f5d17ffd61578432e83c3:/services/keepstore/volume_generic_test.go diff --git a/services/keepstore/volume_generic_test.go b/services/keepstore/volume_generic_test.go index 6dca74eaf2..7ef079f1f7 100644 --- a/services/keepstore/volume_generic_test.go +++ b/services/keepstore/volume_generic_test.go @@ -2,6 +2,8 @@ package main import ( "bytes" + "crypto/md5" + "fmt" "os" "regexp" "sort" @@ -22,6 +24,7 @@ func DoGenericVolumeTests(t *testing.T, factory TestableVolumeFactory) { testGet(t, factory) testGetNoSuchBlock(t, factory) + testCompareNonexistent(t, factory) testCompareSameContent(t, factory, TestHash, TestBlock) testCompareSameContent(t, factory, EmptyHash, EmptyBlock) testCompareWithCollision(t, factory, TestHash, TestBlock, []byte("baddata")) @@ -58,6 +61,8 @@ func DoGenericVolumeTests(t *testing.T, factory TestableVolumeFactory) { testGetConcurrent(t, factory) testPutConcurrent(t, factory) + + testPutFullBlock(t, factory) } // Put a test block, get it and verify content @@ -91,6 +96,19 @@ func testGetNoSuchBlock(t *testing.T, factory TestableVolumeFactory) { } } +// Compare() should return os.ErrNotExist if the block does not exist. +// Otherwise, writing new data causes CompareAndTouch() to generate +// error logs even though everything is working fine. +func testCompareNonexistent(t *testing.T, factory TestableVolumeFactory) { + v := factory(t) + defer v.Teardown() + + err := v.Compare(TestHash, TestBlock) + if err != os.ErrNotExist { + t.Errorf("Got err %T %q, expected os.ErrNotExist", err, err) + } +} + // Put a test block and compare the locator with same content // Test should pass for both writable and read-only volumes func testCompareSameContent(t *testing.T, factory TestableVolumeFactory, testHash string, testData []byte) { @@ -633,3 +651,31 @@ func testPutConcurrent(t *testing.T, factory TestableVolumeFactory) { t.Errorf("Get #3: expected %s, got %s", string(TestBlock3), string(buf)) } } + +// Write and read back a full size block +func testPutFullBlock(t *testing.T, factory TestableVolumeFactory) { + v := factory(t) + defer v.Teardown() + + if !v.Writable() { + return + } + + wdata := make([]byte, BlockSize) + wdata[0] = 'a' + wdata[BlockSize-1] = 'z' + hash := fmt.Sprintf("%x", md5.Sum(wdata)) + err := v.Put(hash, wdata) + if err != nil { + t.Fatal(err) + } + rdata, err := v.Get(hash) + if err != nil { + t.Error(err) + } else { + defer bufs.Put(rdata) + } + if bytes.Compare(rdata, wdata) != 0 { + t.Error("rdata != wdata") + } +}