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 Apr 29, 2024
1 parent 45700b3 commit aaa683b
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 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 @@ -54,23 +55,29 @@ 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
checkIfObjectAttrIsCorrect(fileName, preCreateTime, postCreateTime, BytesWrittenInFile, t)
}

func TestEmptyDirAttributes(t *testing.T) {
func TestAttrEmptyDirAttributes(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)
}
Expand All @@ -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)
}

0 comments on commit aaa683b

Please sign in to comment.