1515package buffered_read
1616
1717import (
18+ "log"
1819 "os"
1920 "path"
2021 "syscall"
@@ -36,17 +37,15 @@ import (
3637// fallbackSuiteBase provides shared setup and teardown logic for fallback-related test suites.
3738type fallbackSuiteBase struct {
3839 suite.Suite
39- testFlags * gcsfuseTestFlags
40+ flags [] string
4041}
4142
4243func (s * fallbackSuiteBase ) SetupSuite () {
4344 if setup .MountedDirectory () != "" {
4445 setupForMountedDirectoryTests ()
4546 return
4647 }
47- configFile := createConfigFile (s .testFlags )
48- flags := []string {"--config-file=" + configFile }
49- setup .MountGCSFuseWithGivenMountFunc (flags , mountFunc )
48+ setup .MountGCSFuseWithGivenMountWithConfigFunc (testEnv .cfg , s .flags , mountFunc )
5049}
5150
5251func (s * fallbackSuiteBase ) SetupTest () {
@@ -59,7 +58,7 @@ func (s *fallbackSuiteBase) TearDownSuite() {
5958 setup .SaveGCSFuseLogFileInCaseOfFailure (s .T ())
6059 return
6160 }
62- setup .UnmountGCSFuse ( rootDir )
61+ setup .UnmountGCSFuseWithConfig ( testEnv . cfg )
6362 setup .SaveGCSFuseLogFileInCaseOfFailure (s .T ())
6463}
6564
@@ -83,7 +82,7 @@ type RandomReadFallbackSuite struct {
8382// the BufferedReader is not created, and reads fall back to the next reader
8483// without any buffered reading.
8584func (s * InsufficientPoolCreationSuite ) TestNewBufferedReader_InsufficientGlobalPool_NoReaderAdded () {
86- fileSize := 3 * s . testFlags . blockSizeMB * util .MiB
85+ fileSize := int64 ( 3 * 8 * util .MiB )
8786 chunkSize := int64 (1 * util .MiB )
8887 testDir := setup .SetupTestDirectory (testDirName )
8988 fileName := setupFileInTestDir (ctx , storageClient , testDir , fileSize , s .T ())
@@ -104,7 +103,7 @@ func (s *InsufficientPoolCreationSuite) TestNewBufferedReader_InsufficientGlobal
104103
105104func (s * RandomReadFallbackSuite ) TestRandomRead_Fallback () {
106105 const randomReadsThreshold = 3
107- blockSizeInBytes := s . testFlags . blockSizeMB * util .MiB
106+ blockSizeInBytes := int64 ( 8 * util .MiB )
108107 // Create a file with 4 blocks. We will read backwards from block 3 to 0
109108 // to trigger random seek detection.
110109 numBlocks := 4
@@ -126,7 +125,7 @@ func (s *RandomReadFallbackSuite) TestRandomRead_Fallback() {
126125}
127126
128127func (s * RandomReadFallbackSuite ) TestRandomRead_SmallFile_NoFallback () {
129- blockSizeInBytes := s . testFlags . blockSizeMB * util .MiB
128+ blockSizeInBytes := int64 ( 8 * util .MiB )
130129 // File size is small, less than one block.
131130 fileSize := blockSizeInBytes / 2
132131 chunkSize := int64 (1 * util .KiB )
@@ -182,46 +181,32 @@ func (s *RandomReadFallbackSuite) TestRandomThenSequential_SwitchesBackToBuffere
182181// Test Function (Runs once before all tests)
183182////////////////////////////////////////////////////////////////////////
184183
185- func TestFallbackSuites (t * testing.T ) {
186- // Define base flags for insufficient pool creation tests.
187- baseInsufficientPoolFlags := gcsfuseTestFlags {
188- enableBufferedRead : true ,
189- blockSizeMB : 8 ,
190- minBlocksPerHandle : 2 ,
191- globalMaxBlocks : 1 , // Less than min-blocks-per-handle
192- maxBlocksPerHandle : 10 ,
193- startBlocksPerHandle : 2 ,
194- }
184+ func TestInsufficientPoolCreationSuite (t * testing.T ) {
185+ ts := & InsufficientPoolCreationSuite {}
195186
196- // Define base flags for random read fallback tests.
197- baseRandomReadFlags := gcsfuseTestFlags {
198- enableBufferedRead : true ,
199- blockSizeMB : 8 ,
200- maxBlocksPerHandle : 20 ,
201- startBlocksPerHandle : 2 ,
202- minBlocksPerHandle : 2 ,
187+ if testEnv .cfg .GKEMountedDirectory != "" && testEnv .cfg .TestBucket != "" {
188+ suite .Run (t , ts )
189+ return
203190 }
204191
205- // Run tests for mounted directory if the flag is set.
206- if setup .AreBothMountedDirectoryAndTestBucketFlagsSet () {
207- suite .Run (t , & InsufficientPoolCreationSuite {fallbackSuiteBase {testFlags : & baseInsufficientPoolFlags }})
208- suite .Run (t , & RandomReadFallbackSuite {fallbackSuiteBase {testFlags : & baseRandomReadFlags }})
209- return
192+ flagsSet := setup .BuildFlagSets (* testEnv .cfg , testEnv .bucketType , t .Name ())
193+ for _ , ts .flags = range flagsSet {
194+ log .Printf ("Running tests with flags: %s" , ts .flags )
195+ suite .Run (t , ts )
210196 }
197+ }
211198
212- protocols := []string {clientProtocolHTTP1 , clientProtocolGRPC }
199+ func TestRandomReadFallbackSuite (t * testing.T ) {
200+ ts := & RandomReadFallbackSuite {}
213201
214- for _ , protocol := range protocols {
215- t .Run (protocol , func (t * testing.T ) {
216- // Run the suite for insufficient pool at creation time.
217- insufficientPoolFlags := baseInsufficientPoolFlags
218- insufficientPoolFlags .clientProtocol = protocol
219- suite .Run (t , & InsufficientPoolCreationSuite {fallbackSuiteBase {testFlags : & insufficientPoolFlags }})
202+ if testEnv .cfg .GKEMountedDirectory != "" && testEnv .cfg .TestBucket != "" {
203+ suite .Run (t , ts )
204+ return
205+ }
220206
221- // Run the suite for random read fallback scenarios.
222- randomReadFlags := baseRandomReadFlags
223- randomReadFlags .clientProtocol = protocol
224- suite .Run (t , & RandomReadFallbackSuite {fallbackSuiteBase {testFlags : & randomReadFlags }})
225- })
207+ flagsSet := setup .BuildFlagSets (* testEnv .cfg , testEnv .bucketType , t .Name ())
208+ for _ , ts .flags = range flagsSet {
209+ log .Printf ("Running tests with flags: %s" , ts .flags )
210+ suite .Run (t , ts )
226211 }
227212}
0 commit comments