Skip to content

Commit ae7bc21

Browse files
committed
migration buffered read
1 parent 3c6a9f4 commit ae7bc21

File tree

5 files changed

+128
-148
lines changed

5 files changed

+128
-148
lines changed

tools/integration_tests/buffered_read/fallback_test.go

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package buffered_read
1616

1717
import (
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.
3738
type fallbackSuiteBase struct {
3839
suite.Suite
39-
testFlags *gcsfuseTestFlags
40+
flags []string
4041
}
4142

4243
func (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

5251
func (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.
8584
func (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

105104
func (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

128127
func (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
}

tools/integration_tests/buffered_read/sequential_read_test.go

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package buffered_read
1616

1717
import (
1818
"fmt"
19+
"log"
1920
"os"
2021
"path"
2122
"syscall"
@@ -36,38 +37,31 @@ import (
3637

3738
type SequentialReadSuite struct {
3839
suite.Suite
39-
// Helper struct with test flags.
40-
testFlags *gcsfuseTestFlags
40+
flags []string
4141
}
4242

4343
func (s *SequentialReadSuite) SetupSuite() {
4444
if setup.MountedDirectory() != "" {
4545
setupForMountedDirectoryTests()
4646
return
4747
}
48-
// Create config file.
49-
configFile := createConfigFile(s.testFlags)
50-
// Create the final flags slice.
51-
// The static mounting helper adds --log-file and --log-severity flags, so we only need to add the format.
52-
flags := []string{"--config-file=" + configFile}
53-
// Mount GCSFuse.
54-
setup.MountGCSFuseWithGivenMountFunc(flags, mountFunc)
48+
setup.MountGCSFuseWithGivenMountWithConfigFunc(testEnv.cfg, s.flags, mountFunc)
5549
}
5650

5751
func (s *SequentialReadSuite) TearDownSuite() {
5852
if setup.MountedDirectory() != "" {
5953
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
6054
return
6155
}
62-
setup.UnmountGCSFuse(rootDir)
56+
setup.UnmountGCSFuseWithConfig(testEnv.cfg)
6357
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
6458
}
6559

6660
// //////////////////////////////////////////////////////////////////////
6761
// Test Cases
6862
// //////////////////////////////////////////////////////////////////////
6963
func (s *SequentialReadSuite) TestSequentialRead() {
70-
blockSizeInBytes := s.testFlags.blockSizeMB * util.MiB
64+
blockSizeInBytes := int64(8 * util.MiB)
7165
fileSizeTests := []struct {
7266
name string
7367
fileSize int64
@@ -112,7 +106,7 @@ func (s *SequentialReadSuite) TestSequentialRead() {
112106
// buffered read log entry, indicating efficient handling.
113107
func (s *SequentialReadSuite) TestReadHeaderFooterAndBody() {
114108
// Constants for block and file sizes
115-
blockSizeInBytes := s.testFlags.blockSizeMB * util.MiB
109+
blockSizeInBytes := int64(8 * util.MiB)
116110
// Header and footer sizes (10KB each)
117111
headerSize := 10 * util.KiB
118112
footerSize := 10 * util.KiB
@@ -160,7 +154,7 @@ func (s *SequentialReadSuite) TestReadHeaderFooterAndBody() {
160154
// TestReadSpanningTwoBlocks verifies that a read spanning two buffer blocks is
161155
// handled correctly.
162156
func (s *SequentialReadSuite) TestReadSpanningTwoBlocks() {
163-
blockSizeInBytes := s.testFlags.blockSizeMB * util.MiB
157+
blockSizeInBytes := int64(8 * util.MiB)
164158
// Ensure file is large enough for multi-block reads.
165159
fileSize := 3 * blockSizeInBytes
166160
// We want to read 512KB, with 256KB in the first block and 256KB in the second.
@@ -186,30 +180,16 @@ func (s *SequentialReadSuite) TestReadSpanningTwoBlocks() {
186180
////////////////////////////////////////////////////////////////////////
187181

188182
func TestSequentialReadSuite(t *testing.T) {
189-
// Define the different flag configurations to test against.
190-
baseTestFlags := gcsfuseTestFlags{
191-
enableBufferedRead: true,
192-
blockSizeMB: 8,
193-
maxBlocksPerHandle: 20,
194-
startBlocksPerHandle: 1,
195-
minBlocksPerHandle: 2,
196-
}
183+
ts := &SequentialReadSuite{}
197184

198-
// Run tests for mounted directory if the flag is set.
199-
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() {
200-
suite.Run(t, &SequentialReadSuite{testFlags: &baseTestFlags})
185+
if testEnv.cfg.GKEMountedDirectory != "" && testEnv.cfg.TestBucket != "" {
186+
suite.Run(t, ts)
201187
return
202188
}
203189

204-
protocols := []string{clientProtocolHTTP1, clientProtocolGRPC}
205-
206-
for _, protocol := range protocols {
207-
// Create a new suite for each protocol.
208-
t.Run(protocol, func(t *testing.T) {
209-
testFlags := baseTestFlags
210-
testFlags.clientProtocol = protocol
211-
212-
suite.Run(t, &SequentialReadSuite{testFlags: &testFlags})
213-
})
190+
flagsSet := setup.BuildFlagSets(*testEnv.cfg, testEnv.bucketType, t.Name())
191+
for _, ts.flags = range flagsSet {
192+
log.Printf("Running tests with flags: %s", ts.flags)
193+
suite.Run(t, ts)
214194
}
215195
}

0 commit comments

Comments
 (0)