Skip to content

Commit e607baf

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

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
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: 14 additions & 13 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
////////////////////////////////////////////////////////////////////////
@@ -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))

0 commit comments

Comments
 (0)