Skip to content

Commit f80dc76

Browse files
committed
use standard setup and teardown functions
1 parent 4d152a0 commit f80dc76

File tree

4 files changed

+52
-45
lines changed

4 files changed

+52
-45
lines changed

tools/integration_tests/buffered_read/fallback_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,20 @@ type fallbackSuiteBase struct {
4141
}
4242

4343
func (s *fallbackSuiteBase) SetupSuite() {
44-
if setup.MountedDirectory() != "" {
45-
setupForMountedDirectoryTests()
46-
return
47-
}
44+
setup.SetUpLogFilePath(s.flags, GKETempDir, "", testEnv.cfg)
4845
setup.MountGCSFuseWithGivenMountWithConfigFunc(testEnv.cfg, s.flags, mountFunc)
46+
setup.SetMntDir(mountDir)
47+
}
48+
49+
func (s *fallbackSuiteBase) TearDownSuite() {
50+
setup.UnmountGCSFuseWithConfig(testEnv.cfg)
4951
}
5052

5153
func (s *fallbackSuiteBase) SetupTest() {
52-
err := os.Truncate(setup.LogFile(), 0)
53-
require.NoError(s.T(), err, "Failed to truncate log file")
54+
testEnv.testDirPath = setup.SetupTestDirectory(testDirName)
5455
}
5556

56-
func (s *fallbackSuiteBase) TearDownSuite() {
57-
if setup.MountedDirectory() != "" {
58-
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
59-
return
60-
}
61-
setup.UnmountGCSFuseWithConfig(testEnv.cfg)
57+
func (s *fallbackSuiteBase) TearDownTest() {
6258
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
6359
}
6460

@@ -82,6 +78,8 @@ type RandomReadFallbackSuite struct {
8278
// the BufferedReader is not created, and reads fall back to the next reader
8379
// without any buffered reading.
8480
func (s *InsufficientPoolCreationSuite) TestNewBufferedReader_InsufficientGlobalPool_NoReaderAdded() {
81+
err := os.Truncate(setup.LogFile(), 0)
82+
require.NoError(s.T(), err, "Failed to truncate log file")
8583
fileSize := blockSizeInBytes * 3
8684
chunkSize := int64(1 * util.MiB)
8785
testDir := setup.SetupTestDirectory(testDirName)
@@ -102,6 +100,8 @@ func (s *InsufficientPoolCreationSuite) TestNewBufferedReader_InsufficientGlobal
102100
}
103101

104102
func (s *RandomReadFallbackSuite) TestRandomRead_Fallback() {
103+
err := os.Truncate(setup.LogFile(), 0)
104+
require.NoError(s.T(), err, "Failed to truncate log file")
105105
const randomReadsThreshold = 3
106106
// Create a file with 4 blocks. We will read backwards from block 3 to 0
107107
// to trigger random seek detection.
@@ -124,6 +124,8 @@ func (s *RandomReadFallbackSuite) TestRandomRead_Fallback() {
124124
}
125125

126126
func (s *RandomReadFallbackSuite) TestRandomRead_SmallFile_NoFallback() {
127+
err := os.Truncate(setup.LogFile(), 0)
128+
require.NoError(s.T(), err, "Failed to truncate log file")
127129
// File size is small, less than one block.
128130
fileSize := blockSizeInBytes / 2
129131
chunkSize := int64(1 * util.KiB)
@@ -149,6 +151,8 @@ func (s *RandomReadFallbackSuite) TestRandomRead_SmallFile_NoFallback() {
149151
// due to random reads, the buffered reader is re-engaged once the read pattern
150152
// becomes sequential again.
151153
func (s *RandomReadFallbackSuite) TestRandomThenSequential_SwitchesBackToBufferedRead() {
154+
err := os.Truncate(setup.LogFile(), 0)
155+
require.NoError(s.T(), err, "Failed to truncate log file")
152156
fileSize := int64(20 * util.MiB)
153157
testDir := setup.SetupTestDirectory(testDirName)
154158
fileName := setupFileInTestDir(testEnv.ctx, testEnv.storageClient, testDir, fileSize, s.T())

tools/integration_tests/buffered_read/sequential_read_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@ type SequentialReadSuite struct {
4141
}
4242

4343
func (s *SequentialReadSuite) SetupSuite() {
44-
if setup.MountedDirectory() != "" {
45-
setupForMountedDirectoryTests()
46-
return
47-
}
44+
setup.SetUpLogFilePath(s.flags, GKETempDir, "", testEnv.cfg)
4845
setup.MountGCSFuseWithGivenMountWithConfigFunc(testEnv.cfg, s.flags, mountFunc)
46+
setup.SetMntDir(mountDir)
4947
}
5048

5149
func (s *SequentialReadSuite) TearDownSuite() {
52-
if setup.MountedDirectory() != "" {
53-
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
54-
return
55-
}
5650
setup.UnmountGCSFuseWithConfig(testEnv.cfg)
51+
}
52+
53+
func (s *SequentialReadSuite) SetupTest() {
54+
testEnv.testDirPath = setup.SetupTestDirectory(testDirName)
55+
}
56+
57+
func (s *SequentialReadSuite) TearDownTest() {
5758
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
5859
}
5960

@@ -85,6 +86,7 @@ func (s *SequentialReadSuite) TestSequentialRead() {
8586

8687
s.T().Run(testName, func(t *testing.T) {
8788
err := os.Truncate(setup.LogFile(), 0)
89+
fmt.Println("pranjall", setup.LogFile())
8890
require.NoError(t, err, "Failed to truncate log file")
8991
testDir := setup.SetupTestDirectory(testDirName)
9092
fileName := setupFileInTestDir(testEnv.ctx, testEnv.storageClient, testDir, fsTest.fileSize, t)

tools/integration_tests/buffered_read/setup_test.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,29 @@ import (
3232
const (
3333
testDirName = "BufferedReadTest"
3434
testFileName = "foo"
35-
logFileNameForMountedDirectoryTests = "/tmp/gcsfuse_buffered_read_test_logs/log.json"
3635
// Global block size constant for tests
3736
blockSizeInBytes = int64(8 * util.MiB)
37+
GKETempDir = "/gcsfuse-tmp"
3838
)
3939

4040
var (
4141
mountFunc func(*test_suite.TestConfig, []string) error
42+
// mount directory is where our tests run.
43+
mountDir string
44+
// root directory is the directory to be unmounted.
45+
rootDir string
4246
)
4347

4448
type env struct {
4549
storageClient *storage.Client
4650
ctx context.Context
51+
testDirPath string
4752
cfg *test_suite.TestConfig
4853
bucketType string
4954
}
5055

5156
var testEnv env
5257

53-
////////////////////////////////////////////////////////////////////////
54-
// Helpers
55-
////////////////////////////////////////////////////////////////////////
56-
57-
func setupForMountedDirectoryTests() {
58-
if setup.MountedDirectory() != "" {
59-
setup.SetLogFile(logFileNameForMountedDirectoryTests)
60-
}
61-
}
62-
6358
////////////////////////////////////////////////////////////////////////
6459
// TestMain
6560
////////////////////////////////////////////////////////////////////////
@@ -77,22 +72,22 @@ func TestMain(m *testing.M) {
7772
cfg.BufferedRead[0].Configs = make([]test_suite.ConfigItem, 3)
7873

7974
cfg.BufferedRead[0].Configs[0].Flags = []string{
80-
"--enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=1 --read-min-blocks-per-handle=2 --enable-kernel-reader=false",
81-
"--client-protocol=grpc --enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=1 --read-min-blocks-per-handle=2 --enable-kernel-reader=false",
75+
"--enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=1 --read-min-blocks-per-handle=2 --enable-kernel-reader=false --log-file=/gcsfuse-tmp/TestBufferedReadSuite.log --log-severity=TRACE",
76+
"--client-protocol=grpc --enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=1 --read-min-blocks-per-handle=2 --enable-kernel-reader=false --log-file=/gcsfuse-tmp/TestBufferedReadSuite.log --log-severity=TRACE",
8277
}
8378
cfg.BufferedRead[0].Configs[0].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
8479
cfg.BufferedRead[0].Configs[0].Run = "TestSequentialReadSuite"
8580

8681
cfg.BufferedRead[0].Configs[1].Flags = []string{
87-
"--enable-buffered-read --read-block-size-mb=8 --read-min-blocks-per-handle=2 --read-global-max-blocks=1 --read-max-blocks-per-handle=10 --read-start-blocks-per-handle=2 --enable-kernel-reader=false",
88-
"--client-protocol=grpc --enable-buffered-read --read-block-size-mb=8 --read-min-blocks-per-handle=2 --read-global-max-blocks=1 --read-max-blocks-per-handle=10 --read-start-blocks-per-handle=2 --enable-kernel-reader=false",
82+
"--enable-buffered-read --read-block-size-mb=8 --read-min-blocks-per-handle=2 --read-global-max-blocks=1 --read-max-blocks-per-handle=10 --read-start-blocks-per-handle=2 --enable-kernel-reader=false --log-file=/gcsfuse-tmp/TestInsufficientPoolCreationSuite.log --log-severity=TRACE",
83+
"--client-protocol=grpc --enable-buffered-read --read-block-size-mb=8 --read-min-blocks-per-handle=2 --read-global-max-blocks=1 --read-max-blocks-per-handle=10 --read-start-blocks-per-handle=2 --enable-kernel-reader=false --log-file=/gcsfuse-tmp/TestInsufficientPoolCreationSuite.log --log-severity=TRACE",
8984
}
9085
cfg.BufferedRead[0].Configs[1].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
9186
cfg.BufferedRead[0].Configs[1].Run = "TestInsufficientPoolCreationSuite"
9287

9388
cfg.BufferedRead[0].Configs[2].Flags = []string{
94-
"--enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=2 --read-min-blocks-per-handle=2 --enable-kernel-reader=false",
95-
"--client-protocol=grpc --enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=2 --read-min-blocks-per-handle=2 --enable-kernel-reader=false",
89+
"--enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=2 --read-min-blocks-per-handle=2 --enable-kernel-reader=false --log-file=/gcsfuse-tmp/TestRandomReadFallbackSuite.log --log-severity=TRACE",
90+
"--client-protocol=grpc --enable-buffered-read --read-block-size-mb=8 --read-max-blocks-per-handle=20 --read-start-blocks-per-handle=2 --read-min-blocks-per-handle=2 --enable-kernel-reader=false --log-file=/gcsfuse-tmp/TestRandomReadFallbackSuite.log --log-severity=TRACE",
9691
}
9792
cfg.BufferedRead[0].Configs[2].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
9893
cfg.BufferedRead[0].Configs[2].Run = "TestRandomReadFallbackSuite"
@@ -113,16 +108,22 @@ func TestMain(m *testing.M) {
113108

114109
// 3. To run mountedDirectory tests, we need both testBucket and mountedDirectory
115110
if testEnv.cfg.GKEMountedDirectory != "" && testEnv.cfg.TestBucket != "" {
111+
// Save mount and root directory variables.
112+
mountDir, rootDir = testEnv.cfg.GKEMountedDirectory, testEnv.cfg.GKEMountedDirectory
116113
os.Exit(setup.RunTestsForMountedDirectory(testEnv.cfg.GKEMountedDirectory, m))
117114
}
118115

119116
// Run tests for testBucket
120117
// Set up test directory.
121118
setup.SetUpTestDirForTestBucket(testEnv.cfg)
119+
// Override GKE specific paths with GCSFuse paths if running in GCE environment.
120+
setup.OverrideFilePathsInFlagSet(testEnv.cfg, setup.TestDir())
122121

123-
mountFunc = static_mounting.MountGcsfuseWithStaticMountingWithConfigFile
122+
// Save mount and root directory variables.
123+
mountDir, rootDir = testEnv.cfg.GCSFuseMountedDirectory, testEnv.cfg.GCSFuseMountedDirectory
124124

125-
// Run the tests.
125+
log.Println("Running static mounting tests...")
126+
mountFunc = static_mounting.MountGcsfuseWithStaticMountingWithConfigFile
126127
successCode := m.Run()
127128

128129
setup.CleanupDirectoryOnGCS(testEnv.ctx, testEnv.storageClient, path.Join(testEnv.cfg.TestBucket, testDirName))

tools/integration_tests/test_config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,26 +1052,26 @@ buffered_read:
10521052
test_bucket: "${BUCKET_NAME}"
10531053
configs:
10541054
- flags:
1055-
- "--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=1,--read-min-blocks-per-handle=2,--enable-kernel-reader=false"
1056-
- "--client-protocol=grpc,--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=1,--read-min-blocks-per-handle=2,--enable-kernel-reader=false"
1055+
- "--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=1,--read-min-blocks-per-handle=2,--enable-kernel-reader=false,--log-file=/gcsfuse-tmp/TestBufferedReadSuite.log,--log-severity=TRACE"
1056+
- "--client-protocol=grpc,--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=1,--read-min-blocks-per-handle=2,--enable-kernel-reader=false,--log-file=/gcsfuse-tmp/TestBufferedReadSuite.log,--log-severity=TRACE"
10571057
compatible:
10581058
flat: true
10591059
hns: true
10601060
zonal: true
10611061
run: TestSequentialReadSuite
10621062
run_on_gke: true
10631063
- flags:
1064-
- "--enable-buffered-read,--read-block-size-mb=8,--read-min-blocks-per-handle=2,--read-global-max-blocks=1,--read-max-blocks-per-handle=10,--read-start-blocks-per-handle=2,--enable-kernel-reader=false"
1065-
- "--client-protocol=grpc,--enable-buffered-read,--read-block-size-mb=8,--read-min-blocks-per-handle=2,--read-global-max-blocks=1,--read-max-blocks-per-handle=10,--read-start-blocks-per-handle=2,--enable-kernel-reader=false"
1064+
- "--enable-buffered-read,--read-block-size-mb=8,--read-min-blocks-per-handle=2,--read-global-max-blocks=1,--read-max-blocks-per-handle=10,--read-start-blocks-per-handle=2,--enable-kernel-reader=false,--log-file=/gcsfuse-tmp/TestInsufficientPoolCreationSuite.log,--log-severity=TRACE"
1065+
- "--client-protocol=grpc,--enable-buffered-read,--read-block-size-mb=8,--read-min-blocks-per-handle=2,--read-global-max-blocks=1,--read-max-blocks-per-handle=10,--read-start-blocks-per-handle=2,--enable-kernel-reader=false,--log-file=/gcsfuse-tmp/TestInsufficientPoolCreationSuite.log,--log-severity=TRACE"
10661066
compatible:
10671067
flat: true
10681068
hns: true
10691069
zonal: true
10701070
run: TestInsufficientPoolCreationSuite
10711071
run_on_gke: true
10721072
- flags:
1073-
- "--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=2,--read-min-blocks-per-handle=2,--enable-kernel-reader=false"
1074-
- "--client-protocol=grpc,--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=2,--read-min-blocks-per-handle=2,--enable-kernel-reader=false"
1073+
- "--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=2,--read-min-blocks-per-handle=2,--enable-kernel-reader=false,--log-file=/gcsfuse-tmp/TestRandomReadFallbackSuite.log,--log-severity=TRACE"
1074+
- "--client-protocol=grpc,--enable-buffered-read,--read-block-size-mb=8,--read-max-blocks-per-handle=20,--read-start-blocks-per-handle=2,--read-min-blocks-per-handle=2,--enable-kernel-reader=false,--log-file=/gcsfuse-tmp/TestRandomReadFallbackSuite.log,--log-severity=TRACE"
10751075
compatible:
10761076
flat: true
10771077
hns: true

0 commit comments

Comments
 (0)