From d9c227eff6080cff326d1b8f50d6ca928c38dd8d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 6 Jul 2025 14:33:54 +0100 Subject: [PATCH] vfs: make integration TestDirEntryModTimeInvalidation test more reliable Before this change it was not taking the Precision of the remote into account. --- vfs/dir_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/vfs/dir_test.go b/vfs/dir_test.go index 8205b33da..3d7ab8cee 100644 --- a/vfs/dir_test.go +++ b/vfs/dir_test.go @@ -669,21 +669,22 @@ func TestDirEntryModTimeInvalidation(t *testing.T) { t.Skip("dirent modtime is unreliable on Windows filesystems") } - // Needs to be less than 2x the wait time below, othewrwise the entry - // gets cleared out before it had a chance to be updated. - vfs.Opt.DirCacheTime = fs.Duration(50 * time.Millisecond) - r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1) + // Read the modtime of the directory fresh + vfs.FlushDirCache() node, err := vfs.Stat("dir") require.NoError(t, err) modTime1 := node.(*Dir).DirEntry().ModTime(context.Background()) - // Wait some time, then write another file which must update ModTime of - // the directory. - time.Sleep(75 * time.Millisecond) + // Wait some time (we wait for Precision+10%), then write another file + // which should update the ModTime of the directory. + prec := (11 * vfs.f.Precision()) / 10 + time.Sleep(max(100*time.Millisecond, prec)) r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2) + // Read the modtime of the directory fresh again - it should have changed + vfs.FlushDirCache() node2, err := vfs.Stat("dir") require.NoError(t, err) modTime2 := node2.(*Dir).DirEntry().ModTime(context.Background())