@@ -31,27 +31,29 @@ import (
3131// Boilerplate
3232// //////////////////////////////////////////////////////////////////////
3333
34- type staleFileHandleEmptyGcsFile struct {
34+ type staleFileHandleEmptyGcsFileTest struct {
3535 staleFileHandleCommon
3636}
3737
3838// //////////////////////////////////////////////////////////////////////
3939// Helpers
4040// //////////////////////////////////////////////////////////////////////
4141
42- func (s * staleFileHandleEmptyGcsFile ) SetupTest () {
42+ func (s * staleFileHandleEmptyGcsFileTest ) SetupTest () {
43+ s .staleFileHandleCommon .SetupTest ()
4344 // Create an empty object on GCS.
4445 s .fileName = path .Base (s .T ().Name ()) + setup .GenerateRandomString (5 )
45- err := CreateObjectOnGCS (ctx , storageClient , path .Join (testDirName , s .fileName ), "" )
46+ err := CreateObjectOnGCS (testEnv . ctx , testEnv . storageClient , path .Join (testDirName , s .fileName ), "" )
4647 assert .NoError (s .T (), err )
47- s .f1 = operations .OpenFileWithODirect (s .T (), path .Join (s .testDirPath , s .fileName ))
48+ s .f1 = operations .OpenFileWithODirect (s .T (), path .Join (testEnv .testDirPath , s .fileName ))
49+ s .isStreamingWritesEnabled = ! slices .Contains (s .flags [0 ], "--enable-streaming-writes=false" )
4850}
4951
5052////////////////////////////////////////////////////////////////////////
5153// Tests
5254////////////////////////////////////////////////////////////////////////
5355
54- func (s * staleFileHandleEmptyGcsFile ) TestClobberedFileReadThrowsStaleFileHandleError () {
56+ func (s * staleFileHandleEmptyGcsFileTest ) TestClobberedFileReadThrowsStaleFileHandleError () {
5557 // TODO(b/410698332): Remove skip condition once takeover support is available.
5658 if s .isStreamingWritesEnabled && setup .IsZonalBucketRun () {
5759 s .T ().Skip ("Skip test due to takeover support not available." )
@@ -62,21 +64,21 @@ func (s *staleFileHandleEmptyGcsFile) TestClobberedFileReadThrowsStaleFileHandle
6264 operations .SyncFile (s .f1 , s .T ())
6365
6466 // Replace the underlying object with a new generation.
65- err = WriteToObject (ctx , storageClient , path .Join (testDirName , s .fileName ), FileContents , storage.Conditions {})
67+ err = WriteToObject (testEnv . ctx , testEnv . storageClient , path .Join (testDirName , s .fileName ), FileContents , storage.Conditions {})
6668
6769 assert .NoError (s .T (), err )
6870 buffer := make ([]byte , len (s .data ))
6971 _ , err = s .f1 .Read (buffer )
7072 operations .ValidateESTALEError (s .T (), err )
7173}
7274
73- func (s * staleFileHandleEmptyGcsFile ) TestClobberedFileFirstWriteThrowsStaleFileHandleError () {
75+ func (s * staleFileHandleEmptyGcsFileTest ) TestClobberedFileFirstWriteThrowsStaleFileHandleError () {
7476 // TODO(b/410698332): Remove skip condition once takeover support is available.
7577 if s .isStreamingWritesEnabled && setup .IsZonalBucketRun () {
7678 s .T ().Skip ("Skip test due to takeover support not available." )
7779 }
7880 // Clobber file by replacing the underlying object with a new generation.
79- err := WriteToObject (ctx , storageClient , path .Join (testDirName , s .fileName ), FileContents , storage.Conditions {})
81+ err := WriteToObject (testEnv . ctx , testEnv . storageClient , path .Join (testDirName , s .fileName ), FileContents , storage.Conditions {})
8082 assert .NoError (s .T (), err )
8183
8284 // Attempt first write to the file should give stale NFS file handle error.
@@ -86,45 +88,35 @@ func (s *staleFileHandleEmptyGcsFile) TestClobberedFileFirstWriteThrowsStaleFile
8688 operations .ValidateSyncGivenThatFileIsClobbered (s .T (), s .f1 , s .isStreamingWritesEnabled )
8789 err = s .f1 .Close ()
8890 operations .ValidateESTALEError (s .T (), err )
89- ValidateObjectContentsFromGCS (ctx , storageClient , testDirName , s .fileName , FileContents , s .T ())
91+ ValidateObjectContentsFromGCS (testEnv . ctx , testEnv . storageClient , testDirName , s .fileName , FileContents , s .T ())
9092}
9193
92- func (s * staleFileHandleEmptyGcsFile ) TestFileDeletedRemotelySyncAndCloseThrowsStaleFileHandleError () {
94+ func (s * staleFileHandleEmptyGcsFileTest ) TestFileDeletedRemotelySyncAndCloseThrowsStaleFileHandleError () {
9395 // TODO(mohitkyadav): Enable test once fix in b/415713332 is released
9496 if s .isStreamingWritesEnabled && setup .IsZonalBucketRun () {
9597 s .T ().Skip ("Skip test due to bug (b/415713332) in client." )
9698 }
9799 // Dirty the file by giving it some contents.
98100 operations .WriteWithoutClose (s .f1 , s .data , s .T ())
99101 // Delete the file remotely.
100- err := DeleteObjectOnGCS (ctx , storageClient , path .Join (testDirName , s .fileName ))
102+ err := DeleteObjectOnGCS (testEnv . ctx , testEnv . storageClient , path .Join (testDirName , s .fileName ))
101103 assert .NoError (s .T (), err )
102104 // Verify unlink operation succeeds.
103- ValidateObjectNotFoundErrOnGCS (ctx , storageClient , testDirName , s .fileName , s .T ())
105+ ValidateObjectNotFoundErrOnGCS (testEnv . ctx , testEnv . storageClient , testDirName , s .fileName , s .T ())
104106 // Attempt to write to file should not give any error.
105107 operations .WriteWithoutClose (s .f1 , s .data , s .T ())
106108
107109 operations .ValidateSyncGivenThatFileIsClobbered (s .T (), s .f1 , s .isStreamingWritesEnabled )
108110
109111 err = s .f1 .Close ()
110112 operations .ValidateESTALEError (s .T (), err )
111- ValidateObjectNotFoundErrOnGCS (ctx , storageClient , testDirName , s .fileName , s .T ())
113+ ValidateObjectNotFoundErrOnGCS (testEnv . ctx , testEnv . storageClient , testDirName , s .fileName , s .T ())
112114}
113115
114116////////////////////////////////////////////////////////////////////////
115117// Test Function (Runs once before all tests)
116118////////////////////////////////////////////////////////////////////////
117119
118120func TestStaleFileHandleEmptyGcsFileTest (t * testing.T ) {
119- // Run tests for mounted directory if the flag is set and return.
120- if setup .AreBothMountedDirectoryAndTestBucketFlagsSet () {
121- suite .Run (t , new (staleFileHandleEmptyGcsFile ))
122- return
123- }
124- for _ , flags := range flagsSet {
125- s := new (staleFileHandleEmptyGcsFile )
126- s .flags = flags
127- s .isStreamingWritesEnabled = ! slices .Contains (s .flags , "--enable-streaming-writes=false" )
128- suite .Run (t , s )
129- }
121+ suite .Run (t , new (staleFileHandleEmptyGcsFileTest ))
130122}
0 commit comments