X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a3222e35cda68c8e48a17921c33ac37ecb5c3bac..aee63d7cbb2f8e39b417baebc145889d6290315e:/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