From 9042e9bf46a1575eef084c097f6696854e254d48 Mon Sep 17 00:00:00 2001 From: Michael Habinsky Date: Fri, 27 Sep 2024 15:48:35 -0600 Subject: [PATCH] Shorten sleeps in tests (#330) --- component/file_cache/file_cache_linux_test.go | 12 +++--- component/file_cache/file_cache_test.go | 42 +++++++++---------- .../file_cache/file_cache_windows_test.go | 4 +- component/file_cache/lru_policy_test.go | 8 ++-- component/s3storage/client_test.go | 2 +- component/s3storage/s3storage_test.go | 2 +- test/e2e_tests/file_test.go | 8 ++-- test/mount_test/mount_test.go | 18 ++++---- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/component/file_cache/file_cache_linux_test.go b/component/file_cache/file_cache_linux_test.go index 9e15197df..ca30db698 100644 --- a/component/file_cache/file_cache_linux_test.go +++ b/component/file_cache/file_cache_linux_test.go @@ -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)) @@ -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)) @@ -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)) diff --git a/component/file_cache/file_cache_test.go b/component/file_cache/file_cache_test.go index 5ca1144f6..c1779153e 100644 --- a/component/file_cache/file_cache_test.go +++ b/component/file_cache/file_cache_test.go @@ -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)) } @@ -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 @@ -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 @@ -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)) @@ -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)) } @@ -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)? @@ -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)) @@ -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) @@ -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 } @@ -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 } @@ -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)) @@ -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) @@ -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()) diff --git a/component/file_cache/file_cache_windows_test.go b/component/file_cache/file_cache_windows_test.go index c1b9cc3f2..29b83af4f 100644 --- a/component/file_cache/file_cache_windows_test.go +++ b/component/file_cache/file_cache_windows_test.go @@ -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 diff --git a/component/file_cache/lru_policy_test.go b/component/file_cache/lru_policy_test.go index 2cfc0541d..43dae3826 100644 --- a/component/file_cache/lru_policy_test.go +++ b/component/file_cache/lru_policy_test.go @@ -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) @@ -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")) } @@ -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))) @@ -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))) diff --git a/component/s3storage/client_test.go b/component/s3storage/client_test.go index 2ffc3be17..310bd01a1 100644 --- a/component/s3storage/client_test.go +++ b/component/s3storage/client_test.go @@ -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), diff --git a/component/s3storage/s3storage_test.go b/component/s3storage/s3storage_test.go index b525008c0..5e6f9f1c2 100644 --- a/component/s3storage/s3storage_test.go +++ b/component/s3storage/s3storage_test.go @@ -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) diff --git a/test/e2e_tests/file_test.go b/test/e2e_tests/file_test.go index 7f804e06b..81a1e8ce4 100644 --- a/test/e2e_tests/file_test.go +++ b/test/e2e_tests/file_test.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/test/mount_test/mount_test.go b/test/mount_test/mount_test.go index 67f8636f1..c103345da 100644 --- a/test/mount_test/mount_test.go +++ b/test/mount_test/mount_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -454,7 +454,7 @@ 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") @@ -462,7 +462,7 @@ 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) @@ -470,7 +470,7 @@ func (suite *mountSuite) TestWriteBackCacheAndIgnoreOpenFlags() { 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)