From bd8523f208b89c535bf4d26bb18d4f25ca36e881 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 24 Apr 2024 11:38:22 +0100 Subject: [PATCH] fstest: reduce precision of directory time checks on CI For unknown reasons the precision of modification times of directories on the CI is > 15mS compared to files which are 100nS. The tests work fine when run in Virtualbox though so I conjecture this is something to do with the file system used there. --- fstest/fstest.go | 11 ++++++++++- fstest/testy/testy.go | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fstest/fstest.go b/fstest/fstest.go index ef4d11418..d29c25422 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -27,6 +27,7 @@ import ( "github.com/rclone/rclone/fs/config/configfile" "github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/fs/walk" + "github.com/rclone/rclone/fstest/testy" "github.com/rclone/rclone/lib/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -620,7 +621,15 @@ func CheckDirModTime(ctx context.Context, t *testing.T, f fs.Fs, dir fs.Director return } gotT := dir.ModTime(ctx) - AssertTimeEqualWithPrecision(t, dir.Remote(), wantT, gotT, f.Precision()) + precision := f.Precision() + // For unknown reasons the precision of modification times of + // directories on the CI is about >15mS. The tests work fine + // when run in Virtualbox though so I conjecture this is + // something to do with the file system used there. + if runtime.GOOS == "windows" && testy.CI() { + precision = 100 * time.Millisecond + } + AssertTimeEqualWithPrecision(t, dir.Remote(), wantT, gotT, precision) } // Gz returns a compressed version of its input string diff --git a/fstest/testy/testy.go b/fstest/testy/testy.go index ca2d4ebe8..5b73c0139 100644 --- a/fstest/testy/testy.go +++ b/fstest/testy/testy.go @@ -6,9 +6,14 @@ import ( "testing" ) +// CI returns true if we are running on the CI server +func CI() bool { + return os.Getenv("CI") != "" +} + // SkipUnreliable skips this test if running on CI func SkipUnreliable(t *testing.T) { - if os.Getenv("CI") == "" { + if !CI() { return } t.Skip("Skipping Unreliable Test on CI")