From 32d141b2e14d56797bd7e06d50d9f45997838e60 Mon Sep 17 00:00:00 2001 From: Ashmeen Kaur Date: Mon, 29 Apr 2024 10:04:17 +0000 Subject: [PATCH] changes to use time slop --- .../file_and_dir_attributes_test.go | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/integration_tests/operations/file_and_dir_attributes_test.go b/tools/integration_tests/operations/file_and_dir_attributes_test.go index bd527a880e..6915a5076f 100644 --- a/tools/integration_tests/operations/file_and_dir_attributes_test.go +++ b/tools/integration_tests/operations/file_and_dir_attributes_test.go @@ -23,8 +23,6 @@ import ( "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/operations" "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup" - "github.com/jacobsa/fuse/fusetesting" - "github.com/jacobsa/ogletest" ) const DirAttrTest = "dirAttrTest" @@ -42,8 +40,11 @@ func checkIfObjectAttrIsCorrect(objName string, preCreateTime time.Time, postCre if objName != statObjName { t.Errorf("File name not matched in os.Stat, found: %s, expected: %s", statObjName, objName) } - ogletest.ExpectThat(oStat, fusetesting.MtimeIsWithin(preCreateTime, operations.TimeSlop)) - ogletest.ExpectThat(oStat, fusetesting.MtimeIsWithin(postCreateTime, operations.TimeSlop)) + + statModTime := oStat.ModTime() + if (preCreateTime.After(statModTime)) || (postCreateTime.Before(statModTime)) { + t.Errorf("File modification time not in the expected time-range") + } if oStat.Size() != byteSize { t.Errorf("File size is not %v bytes, found size: %d bytes", BytesWrittenInFile, oStat.Size()) @@ -54,9 +55,12 @@ func TestFileAttributes(t *testing.T) { // Clean the mountedDirectory before running test. setup.CleanMntDir() - preCreateTime := time.Now() + // kernel time can be slightly out of sync of time.Now(), so using + // operations.TimeSlop to adjust pre and post create time. + // Ref: https://github.com/golang/go/issues/33510 + preCreateTime := time.Now().Add(-operations.TimeSlop) fileName := setup.CreateTempFile() - postCreateTime := time.Now() + postCreateTime := time.Now().Add(+operations.TimeSlop) // The file size in createTempFile() is BytesWrittenInFile bytes // https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/tools/integration_tests/util/setup/setup.go#L124 @@ -67,10 +71,13 @@ func TestEmptyDirAttributes(t *testing.T) { // Clean the mountedDirectory before running test. setup.CleanMntDir() - preCreateTime := time.Now() + // kernel time can be slightly out of sync of time.Now(), so using + // operations.TimeSlop to adjust pre and post create time. + // Ref: https://github.com/golang/go/issues/33510 + preCreateTime := time.Now().Add(-operations.TimeSlop) dirName := path.Join(setup.MntDir(), DirAttrTest) operations.CreateDirectoryWithNFiles(0, dirName, "", t) - postCreateTime := time.Now() + postCreateTime := time.Now().Add(operations.TimeSlop) checkIfObjectAttrIsCorrect(dirName, preCreateTime, postCreateTime, 0, t) } @@ -79,10 +86,13 @@ func TestNonEmptyDirAttributes(t *testing.T) { // Clean the mountedDirectory before running test. setup.CleanMntDir() - preCreateTime := time.Now() + // kernel time can be slightly out of sync of time.Now(), so using + // operations.TimeSlop to adjust pre and post create time. + // Ref: https://github.com/golang/go/issues/33510 + preCreateTime := time.Now().Add(-operations.TimeSlop) dirName := path.Join(setup.MntDir(), DirAttrTest) operations.CreateDirectoryWithNFiles(NumberOfFilesInDirAttrTest, dirName, PrefixFileInDirAttrTest, t) - postCreateTime := time.Now() + postCreateTime := time.Now().Add(operations.TimeSlop) checkIfObjectAttrIsCorrect(dirName, preCreateTime, postCreateTime, 0, t) }