X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e4382e25d68a70a107baeb257e1915972759334c..1e31ae09539d8265820a2f75f8a981f7d415ef58:/services/keepstore/volume_unix_test.go diff --git a/services/keepstore/volume_unix_test.go b/services/keepstore/volume_unix_test.go index d6aeac6185..7a10fc5c60 100644 --- a/services/keepstore/volume_unix_test.go +++ b/services/keepstore/volume_unix_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "syscall" "testing" "time" ) @@ -110,32 +111,41 @@ func TestPutTouch(t *testing.T) { 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) + + // We'll verify { t0 < threshold < t1 }, where t0 is the + // existing block's timestamp on disk before Put() and t1 is + // its timestamp after Put(). + threshold := time.Now().Add(-time.Second) + + // Set the stored block's mtime far enough in the past that we + // can see the difference between "timestamp didn't change" + // and "timestamp granularity is too low". + { + oldtime := time.Now().Add(-20 * time.Second).Unix() + if err := syscall.Utime(v.blockPath(TEST_HASH), + &syscall.Utimbuf{oldtime, oldtime}); err != nil { + t.Error(err) + } + + // Make sure v.Mtime() agrees the above Utime really worked. + if t0, err := v.Mtime(TEST_HASH); err != nil || t0.IsZero() || !t0.Before(threshold) { + t.Errorf("Setting mtime failed: %v, %v", t0, err) + } } - // 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) + + // Write the same block again. if err := v.Put(TEST_HASH, TEST_BLOCK); err != nil { t.Error(err) } - new_mtime, err := v.Mtime(TEST_HASH) + + // Verify threshold < t1 + t1, 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) + if t1.Before(threshold) { + t.Errorf("t1 %v must be >= threshold %v after v.Put ", + t1, threshold) } }