X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/922da69f42998b29355796e20e4dee0079d4113e..5596c93b7938d6c6758a93a0e33cf4a5c185c445:/services/keepstore/volume_unix_test.go diff --git a/services/keepstore/volume_unix_test.go b/services/keepstore/volume_unix_test.go index 278e656066..d6aeac6185 100644 --- a/services/keepstore/volume_unix_test.go +++ b/services/keepstore/volume_unix_test.go @@ -100,6 +100,45 @@ func TestPutBadVolume(t *testing.T) { } } +// TestPutTouch +// Test that when applying PUT to a block that already exists, +// the block's modification time is updated. +func TestPutTouch(t *testing.T) { + v := TempUnixVolume(t, false) + defer _teardown(v) + + if err := v.Put(TEST_HASH, TEST_BLOCK); err != nil { + t.Error(err) + } + old_mtime, err := v.Mtime(TEST_HASH) + if err != nil { + t.Error(err) + } + if old_mtime.IsZero() { + t.Errorf("v.Mtime(%s) returned a zero mtime\n", TEST_HASH) + } + // Sleep for 1s, then put the block again. The volume + // should report a more recent mtime. + // + // TODO(twp): this would be better handled with a mock Time object. + // Alternatively, set the mtime manually to some moment in the past + // (maybe a v.SetMtime method?) + // + time.Sleep(time.Second) + if err := v.Put(TEST_HASH, TEST_BLOCK); err != nil { + t.Error(err) + } + new_mtime, err := v.Mtime(TEST_HASH) + if err != nil { + t.Error(err) + } + + if !new_mtime.After(old_mtime) { + t.Errorf("v.Put did not update the block mtime:\nold_mtime = %v\nnew_mtime = %v\n", + old_mtime, new_mtime) + } +} + // Serialization tests: launch a bunch of concurrent // // TODO(twp): show that the underlying Read/Write operations executed