Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent minor race condition in file cache tests #332

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions component/file_cache/file_cache_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func (suite *fileCacheLinuxTestSuite) TestChmodInCache() {
// Setup
path := "file34"
createHandle, _ := suite.fileCache.CreateFile(internal.CreateFileOptions{Name: path, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
openHandle, _ := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: path, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})

// Path should be in the file cache
suite.assert.FileExists(suite.cache_path + "/" + path)
Expand Down Expand Up @@ -238,10 +238,8 @@ func (suite *fileCacheLinuxTestSuite) TestChownInCache() {
// Setup
path := "file37"
createHandle, _ := suite.fileCache.CreateFile(internal.CreateFileOptions{Name: path, Mode: 0777})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
openHandle, _ := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: path, Mode: 0777})
err := suite.fileCache.downloadFile(openHandle)
suite.assert.NoError(err)
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})

// Path should be in the file cache
suite.assert.FileExists(suite.cache_path + "/" + path)
Expand All @@ -251,7 +249,7 @@ func (suite *fileCacheLinuxTestSuite) TestChownInCache() {
// Chown
owner := os.Getuid()
group := os.Getgid()
err = suite.fileCache.Chown(internal.ChownOptions{Name: path, Owner: owner, Group: group})
err := suite.fileCache.Chown(internal.ChownOptions{Name: path, Owner: owner, Group: group})
suite.assert.NoError(err)
// Path in fake storage and file cache should be updated
info, err := os.Stat(suite.cache_path + "/" + path)
Expand Down
12 changes: 5 additions & 7 deletions component/file_cache/file_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,10 +1313,10 @@ func (suite *fileCacheTestSuite) TestRenameFileInCache() {
dst := "destination2"
createHandle, err := suite.fileCache.CreateFile(internal.CreateFileOptions{Name: src, Mode: 0666})
suite.assert.NoError(err)
err = suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
suite.assert.NoError(err)
openHandle, err := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: src, Mode: 0666})
suite.assert.NoError(err)
err = suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
suite.assert.NoError(err)

// Path should be in the file cache
suite.assert.FileExists(filepath.Join(suite.cache_path, src))
Expand Down Expand Up @@ -1365,8 +1365,8 @@ func (suite *fileCacheTestSuite) TestRenameFileAndCacheCleanup() {
src := "source4"
dst := "destination4"
createHandle, _ := suite.fileCache.CreateFile(internal.CreateFileOptions{Name: src, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
openHandle, _ := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: src, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})

// Path should be in the file cache
suite.assert.FileExists(suite.cache_path + "/" + src)
Expand Down Expand Up @@ -1402,8 +1402,8 @@ func (suite *fileCacheTestSuite) TestRenameFileAndCacheCleanupWithNoTimeout() {
src := "source5"
dst := "destination5"
createHandle, _ := suite.fileCache.CreateFile(internal.CreateFileOptions{Name: src, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
openHandle, _ := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: src, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})

// Path should be in the file cache
suite.assert.FileExists(suite.cache_path + "/" + src)
Expand Down Expand Up @@ -1457,8 +1457,8 @@ func (suite *fileCacheTestSuite) TestTruncateFileInCache() {
// Setup
path := "file31"
createHandle, _ := suite.fileCache.CreateFile(internal.CreateFileOptions{Name: path, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
openHandle, _ := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: path, Mode: 0666})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})

// Path should be in the file cache
suite.assert.FileExists(filepath.Join(suite.cache_path, path))
Expand Down Expand Up @@ -1693,8 +1693,6 @@ func (suite *fileCacheTestSuite) TestHardLimitOnSize() {
smallHandle, err := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: pathsmall, Flags: os.O_RDONLY, Mode: suite.fileCache.defaultPermission})
suite.assert.NoError(err)
// try opening small file
err = suite.fileCache.downloadFile(smallHandle)
suite.assert.NoError(err)
suite.assert.False(smallHandle.Dirty())
err = suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: smallHandle})
suite.assert.NoError(err)
Expand Down
9 changes: 3 additions & 6 deletions component/file_cache/file_cache_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,22 @@ func (suite *fileCacheWindowsTestSuite) TestChownInCache() {
// Setup
path := "file"
createHandle, _ := suite.fileCache.CreateFile(internal.CreateFileOptions{Name: path, Mode: 0777})
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})
openHandle, _ := suite.fileCache.OpenFile(internal.OpenFileOptions{Name: path, Mode: 0777})
err := suite.fileCache.downloadFile(openHandle)
suite.assert.NoError(err)
suite.fileCache.CloseFile(internal.CloseFileOptions{Handle: createHandle})

// Path should be in the file cache
suite.assert.FileExists(suite.cache_path + "/" + path)
// Path should be in fake storage
suite.assert.FileExists(suite.fake_storage_path + "/" + path)

// Chown is not supportred on Windows, but checking that calling it does not cause an error
// Chown is not supported on Windows, but checking that calling it does not cause an error
owner := os.Getuid()
group := os.Getgid()
err = suite.fileCache.Chown(internal.ChownOptions{Name: path, Owner: owner, Group: group})
err := suite.fileCache.Chown(internal.ChownOptions{Name: path, Owner: owner, Group: group})
suite.assert.NoError(err)

// Checking that nothing changed with existing files
suite.assert.FileExists(suite.cache_path + "/" + path)

suite.assert.FileExists(suite.fake_storage_path + "/" + path)

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