Skip to content

Commit

Permalink
Shorten sleeps in tests (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
foodprocessor authored Sep 27, 2024
1 parent e77cb1c commit 9042e9b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 48 deletions.
12 changes: 6 additions & 6 deletions component/file_cache/file_cache_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func (suite *fileCacheLinuxTestSuite) TestChmodNotInCache() {
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: handle})

_, err := os.Stat(suite.cache_path + "/" + path)
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(suite.cache_path + "/" + path)
}
suite.assert.True(os.IsNotExist(err))
Expand Down Expand Up @@ -188,8 +188,8 @@ func (suite *fileCacheLinuxTestSuite) TestChmodCase2() {

// loop until file does not exist - done due to async nature of eviction
_, err = os.Stat(suite.cache_path + "/" + path)
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(suite.cache_path + "/" + path)
}
suite.assert.True(os.IsNotExist(err))
Expand All @@ -210,8 +210,8 @@ func (suite *fileCacheLinuxTestSuite) TestChownNotInCache() {
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: handle})

_, err := os.Stat(suite.cache_path + "/" + path)
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(suite.cache_path + "/" + path)
}
suite.assert.True(os.IsNotExist(err))
Expand Down
42 changes: 21 additions & 21 deletions component/file_cache/file_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (suite *fileCacheTestSuite) TestDeleteDir() {
err = suite.fileCache.DeleteDir(internal.DeleteDirOptions{Name: dir})
suite.assert.NoError(err)
// wait for asynchronous deletion
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
// Directory should not be cached
suite.assert.NoDirExists(filepath.Join(suite.cache_path, dir))
}
Expand Down Expand Up @@ -603,7 +603,7 @@ func (suite *fileCacheTestSuite) TestRenameDir() {
err = suite.fileCache.RenameDir(internal.RenameDirOptions{Src: src, Dst: dst})
suite.assert.NoError(err)
// wait for asynchronous deletion
time.Sleep(1 * time.Second)
time.Sleep(100 * time.Millisecond)
// src directory should not exist in local filesystem
suite.assert.NoDirExists(filepath.Join(suite.cache_path, src))
// dst directory should exist and have contents from src
Expand Down Expand Up @@ -867,8 +867,8 @@ func (suite *fileCacheTestSuite) TestOpenFileNotInCache() {

// loop until file does not exist - done due to async nature of eviction
_, err := os.Stat(filepath.Join(suite.cache_path, path))
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(filepath.Join(suite.cache_path, path))
}
// TODO: find out why this delayed eviction check fails in CI on Windows sometimes
Expand Down Expand Up @@ -926,8 +926,8 @@ func (suite *fileCacheTestSuite) TestCloseFile() {

// loop until file does not exist - done due to async nature of eviction
_, err = os.Stat(filepath.Join(suite.cache_path, path))
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(filepath.Join(suite.cache_path, path))
}
suite.assert.True(os.IsNotExist(err))
Expand Down Expand Up @@ -962,8 +962,8 @@ func (suite *fileCacheTestSuite) TestCloseFileTimeout() {

// loop until file does not exist - done due to async nature of eviction
_, err = os.Stat(filepath.Join(suite.cache_path, path))
for i := 0; i < (cacheTimeout*3) && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < (cacheTimeout*300) && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(filepath.Join(suite.cache_path, path))
}

Expand Down Expand Up @@ -1248,8 +1248,8 @@ func (suite *fileCacheTestSuite) TestGetAttrCase4() {

// Wait file is evicted
_, err = os.Stat(filepath.Join(suite.cache_path, file))
for i := 0; i < 20 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 2000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(filepath.Join(suite.cache_path, file))
}
// TODO: why is check test flaky (on both platforms)?
Expand Down Expand Up @@ -1288,8 +1288,8 @@ func (suite *fileCacheTestSuite) TestRenameFileNotInCache() {
suite.assert.NoError(err)

_, err = os.Stat(filepath.Join(suite.cache_path, src))
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(filepath.Join(suite.cache_path, src))
}
suite.assert.True(os.IsNotExist(err))
Expand Down Expand Up @@ -1358,7 +1358,7 @@ func (suite *fileCacheTestSuite) TestRenameFileAndCacheCleanup() {
defer suite.cleanupTest()
suite.cleanupTest()

config := fmt.Sprintf("file_cache:\n path: %s\n offload-io: true\n timeout-sec: 10\n\nloopbackfs:\n path: %s",
config := fmt.Sprintf("file_cache:\n path: %s\n offload-io: true\n timeout-sec: 2\n\nloopbackfs:\n path: %s",
suite.cache_path, suite.fake_storage_path)
suite.setupTestHelper(config) // setup a new file cache with a custom config (teardown will occur after the test as usual)

Expand All @@ -1384,10 +1384,10 @@ func (suite *fileCacheTestSuite) TestRenameFileAndCacheCleanup() {

suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: openHandle})

time.Sleep(5 * time.Second) // Check once before the cache cleanup that file exists
time.Sleep(1 * time.Second) // Check once before the cache cleanup that file exists
suite.assert.FileExists(suite.cache_path + "/" + dst) // Dst shall exists in cache

time.Sleep(8 * time.Second) // Wait for the cache cleanup to occur
time.Sleep(2 * time.Second) // Wait for the cache cleanup to occur
suite.assert.FileExists(suite.cache_path + "/" + dst) // Dst shall not exists in cache
}

Expand Down Expand Up @@ -1421,7 +1421,7 @@ func (suite *fileCacheTestSuite) TestRenameFileAndCacheCleanupWithNoTimeout() {

suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: openHandle})

time.Sleep(1 * time.Second) // Wait for the cache cleanup to occur
time.Sleep(100 * time.Millisecond) // Wait for the cache cleanup to occur
suite.assert.NoFileExists(suite.cache_path + "/" + dst) // Dst shall not exists in cache
}

Expand All @@ -1433,8 +1433,8 @@ func (suite *fileCacheTestSuite) TestTruncateFileNotInCache() {
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: handle})

_, err := os.Stat(filepath.Join(suite.cache_path, path))
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(filepath.Join(suite.cache_path, path))
}
suite.assert.True(os.IsNotExist(err))
Expand Down Expand Up @@ -1622,7 +1622,7 @@ func (suite *fileCacheTestSuite) TestReadFileWithRefresh() {
defer suite.cleanupTest()
// Configure to create empty files so we create the file in cloud storage
createEmptyFile := true
config := fmt.Sprintf("file_cache:\n path: %s\n offload-io: true\n create-empty-file: %t\n timeout-sec: 1000\n refresh-sec: 10\n\nloopbackfs:\n path: %s",
config := fmt.Sprintf("file_cache:\n path: %s\n offload-io: true\n create-empty-file: %t\n timeout-sec: 1000\n refresh-sec: 1\n\nloopbackfs:\n path: %s",
suite.cache_path, createEmptyFile, suite.fake_storage_path)
suite.setupTestHelper(config) // setup a new file cache with a custom config (teardown will occur after the test as usual)

Expand Down Expand Up @@ -1658,11 +1658,11 @@ func (suite *fileCacheTestSuite) TestReadFileWithRefresh() {
err = suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: f})
suite.assert.NoError(err)

// Now wait for 5 seconds and we shall get the updated content on next read
// Now wait for refresh timeout and we shall get the updated content on next read
byteArr = []byte("test data123456")
err = os.WriteFile(suite.fake_storage_path+"/"+path, []byte("test data123456"), 0777)
suite.assert.NoError(err)
time.Sleep(12 * time.Second)
time.Sleep(2 * time.Second)
f, err = suite.fileCache.OpenFile(options)
suite.assert.NoError(err)
suite.assert.False(f.Dirty())
Expand Down
4 changes: 2 additions & 2 deletions component/file_cache/file_cache_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (suite *fileCacheWindowsTestSuite) TestChownNotInCache() {
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: handle})

_, err := os.Stat(suite.cache_path + "/" + path)
for i := 0; i < 10 && !os.IsNotExist(err); i++ {
time.Sleep(time.Second)
for i := 0; i < 1000 && !os.IsNotExist(err); i++ {
time.Sleep(10 * time.Millisecond)
_, err = os.Stat(suite.cache_path + "/" + path)
}
// this check is flaky in our CI pipeline on Windows, so skip it
Expand Down
8 changes: 4 additions & 4 deletions component/file_cache/lru_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (suite *lruPolicyTestSuite) TestCachePurge() {

// wait for asynchronous deletions
// in local testing, 1ms was enough
time.Sleep(1 * time.Second)
time.Sleep(100 * time.Millisecond)
// validate all aPaths were deleted
for _, path := range aPaths {
suite.assert.NoFileExists(path)
Expand Down Expand Up @@ -293,7 +293,7 @@ func (suite *lruPolicyTestSuite) TestTimeout() {

suite.policy.CacheValid("temp")

time.Sleep(5 * time.Second) // Wait for time > cacheTimeout, the file should no longer be cached
time.Sleep(3 * time.Second) // Wait for time > cacheTimeout, the file should no longer be cached

suite.assert.False(suite.policy.IsCached("temp"))
}
Expand All @@ -318,7 +318,7 @@ func (suite *lruPolicyTestSuite) TestMaxEvictionDefault() {
suite.policy.CacheValid("temp" + fmt.Sprint(i))
}

time.Sleep(5 * time.Second) // Wait for time > cacheTimeout, the file should no longer be cached
time.Sleep(3 * time.Second) // Wait for time > cacheTimeout, the file should no longer be cached

for i := 1; i < 5000; i++ {
suite.assert.False(suite.policy.IsCached("temp" + fmt.Sprint(i)))
Expand All @@ -345,7 +345,7 @@ func (suite *lruPolicyTestSuite) TestMaxEviction() {
suite.policy.CacheValid("temp" + fmt.Sprint(i))
}

time.Sleep(5 * time.Second) // Wait for time > cacheTimeout, the file should no longer be cached
time.Sleep(3 * time.Second) // Wait for time > cacheTimeout, the file should no longer be cached

for i := 1; i < 5; i++ {
suite.assert.False(suite.policy.IsCached("temp" + fmt.Sprint(i)))
Expand Down
2 changes: 1 addition & 1 deletion component/s3storage/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ func (s *clientTestSuite) TestGetAttrFile() {
// file time
s.assert.NotNil(before.Mtime)

time.Sleep(time.Second * 3) // Wait 3 seconds and then modify the file again
time.Sleep(1 * time.Second) // Wait and then modify the file again

_, err = s.awsS3Client.PutObject(context.Background(), &s3.PutObjectInput{
Bucket: aws.String(s.client.Config.authConfig.BucketName),
Expand Down
2 changes: 1 addition & 1 deletion component/s3storage/s3storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ func (s *s3StorageTestSuite) TestGetAttrFileTime() {
s.assert.NoError(err)
s.assert.NotNil(before.Mtime)

time.Sleep(time.Second * 3) // Wait 3 seconds and then modify the file again
time.Sleep(1 * time.Second) // Wait and then modify the file again

_, err = s.s3Storage.WriteFile(internal.WriteFileOptions{Handle: h, Offset: 0, Data: data})
s.assert.NoError(err)
Expand Down
8 changes: 4 additions & 4 deletions test/e2e_tests/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (suite *fileTestSuite) TestFileCreatSpclChar() {
srcFile, err := os.OpenFile(fileName, os.O_CREATE, 0777)
suite.NoError(err)
srcFile.Close()
time.Sleep(time.Second * 2)
time.Sleep(time.Second * 1)

suite.FileExists(fileName)

Expand All @@ -160,7 +160,7 @@ func (suite *fileTestSuite) TestFileCreateEncodeChar() {
srcFile, err := os.OpenFile(fileName, os.O_CREATE, 0777)
suite.NoError(err)
srcFile.Close()
time.Sleep(time.Second * 2)
time.Sleep(time.Second * 1)

suite.FileExists(fileName)

Expand Down Expand Up @@ -200,7 +200,7 @@ func (suite *fileTestSuite) TestFileCreateMultiSpclCharWithinSpclDir() {
srcFile, err = os.OpenFile(fileName, os.O_CREATE, 0777)
suite.NoError(err)
srcFile.Close()
time.Sleep(time.Second * 2)
time.Sleep(time.Second * 1)

suite.FileExists(fileName)

Expand Down Expand Up @@ -361,7 +361,7 @@ func (suite *fileTestSuite) TestFileGetStat() {
f, err := os.Create(fileName)
suite.NoError(err)
f.Close()
time.Sleep(time.Second * 3)
time.Sleep(time.Second * 1)

stat, err := os.Stat(fileName)
suite.NoError(err)
Expand Down
18 changes: 9 additions & 9 deletions test/mount_test/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (suite *mountSuite) TestMountCmd() {
suite.NoError(err)

// wait for mount
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)

// validate mount
cliOut = listCloudfuseMounts(suite)
Expand Down Expand Up @@ -203,7 +203,7 @@ func (suite *mountSuite) TestMountDirNotEmptySuccess() {
suite.NoError(err)

// wait for mount
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)

// validate mount
cliOut = listCloudfuseMounts(suite)
Expand Down Expand Up @@ -316,7 +316,7 @@ func (suite *mountSuite) TestEnvVarMount() {
suite.NoError(err)

// wait for mount
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)

// list cloudfuse mounted directories
cliOut = listCloudfuseMounts(suite)
Expand All @@ -333,7 +333,7 @@ func (suite *mountSuite) TestEnvVarMount() {
suite.NoError(err)

// wait for mount
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)

// list cloudfuse mounted directories
cliOut = listCloudfuseMounts(suite)
Expand Down Expand Up @@ -389,7 +389,7 @@ func (suite *mountSuite) TestEnvVarMount() {
// suite.Equal(nil, err)

// // wait for mount
// time.Sleep(10 * time.Second)
// time.Sleep(5 * time.Second)

// // list cloudfuse mounted directories
// cliOut = listCloudfuseMounts(suite)
Expand All @@ -416,7 +416,7 @@ func mountAndValidate(suite *mountSuite, args ...string) {
suite.NoError(err)

// wait for mount
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)

// validate mount
cliOut = listCloudfuseMounts(suite)
Expand Down Expand Up @@ -454,23 +454,23 @@ func (suite *mountSuite) TestWriteBackCacheAndIgnoreOpenFlags() {
suite.NoError(err)
suite.NotNil(f)
f.Close()
time.Sleep(2 * time.Second)
time.Sleep(1 * time.Second)
cloudfuseUnmount(suite, mntDir)

mountAndValidate(suite, "--disable-writeback-cache=false", "--ignore-open-flags=true")
f, err = os.OpenFile(remoteFilePath, os.O_APPEND, 0777)
suite.NoError(err)
suite.NotNil(f)
f.Close()
time.Sleep(2 * time.Second)
time.Sleep(1 * time.Second)
cloudfuseUnmount(suite, mntDir)

mountAndValidate(suite)
f, err = os.OpenFile(remoteFilePath, os.O_APPEND, 0777)
suite.NoError(err)
suite.NotNil(f)
f.Close()
time.Sleep(2 * time.Second)
time.Sleep(1 * time.Second)

err = os.RemoveAll(remoteFilePath)
suite.NoError(err)
Expand Down

0 comments on commit 9042e9b

Please sign in to comment.