Skip to content

Commit

Permalink
changes to use time slop
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed May 2, 2024
1 parent e30e086 commit e99b351
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions tools/integration_tests/operations/file_and_dir_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand All @@ -53,10 +54,13 @@ func checkIfObjectAttrIsCorrect(objName string, preCreateTime time.Time, postCre
func TestFileAttributes(t *testing.T) {
testDir := setup.SetupTestDirectory(DirForOperationTests)

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 := path.Join(testDir, tempFileName)
operations.CreateFileWithContent(fileName, setup.FilePermission_0600, Content, t)
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
Expand All @@ -66,21 +70,27 @@ func TestFileAttributes(t *testing.T) {
func TestEmptyDirAttributes(t *testing.T) {
testDir := setup.SetupTestDirectory(DirForOperationTests)

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(testDir, DirAttrTest)
operations.CreateDirectoryWithNFiles(0, dirName, "", t)
postCreateTime := time.Now()
postCreateTime := time.Now().Add(operations.TimeSlop)

checkIfObjectAttrIsCorrect(path.Join(testDir, DirAttrTest), preCreateTime, postCreateTime, 0, t)
}

func TestNonEmptyDirAttributes(t *testing.T) {
testDir := setup.SetupTestDirectory(DirForOperationTests)

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(testDir, DirAttrTest)
operations.CreateDirectoryWithNFiles(NumberOfFilesInDirAttrTest, dirName, PrefixFileInDirAttrTest, t)
postCreateTime := time.Now()
postCreateTime := time.Now().Add(operations.TimeSlop)

checkIfObjectAttrIsCorrect(dirName, preCreateTime, postCreateTime, 0, t)
}

0 comments on commit e99b351

Please sign in to comment.