Skip to content

Commit 37024db

Browse files
committed
initial changes
1 parent 2aa0bb7 commit 37024db

File tree

5 files changed

+109
-81
lines changed

5 files changed

+109
-81
lines changed

tools/integration_tests/stale_handle/setup_test.go

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"cloud.google.com/go/storage"
2424
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
25-
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/mounting/static_mounting"
2625
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
2726
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/test_suite"
2827
)
@@ -32,57 +31,75 @@ const (
3231
)
3332

3433
var (
34+
testEnv env
35+
)
36+
37+
type env struct {
3538
storageClient *storage.Client
3639
ctx context.Context
37-
rootDir string
38-
mountFunc func([]string) error
39-
flagsSet [][]string
40-
)
40+
testDirPath string
41+
cfg *test_suite.TestConfig
42+
bucketType string
43+
}
4144

4245
func TestMain(m *testing.M) {
4346
setup.ParseSetUpFlags()
4447

4548
// 1. Load and parse the common configuration.
4649
cfg := test_suite.ReadConfigFile(setup.ConfigFile())
4750
if len(cfg.StaleHandle) == 0 {
48-
log.Println("No configuration found for write large files tests in config. Using flags instead.")
51+
log.Println("No configuration found for stale_handle tests in config. Using flags instead.")
4952
// Populate the config manually.
5053
cfg.StaleHandle = make([]test_suite.TestConfig, 1)
5154
cfg.StaleHandle[0].TestBucket = setup.TestBucket()
5255
cfg.StaleHandle[0].GKEMountedDirectory = setup.MountedDirectory()
53-
cfg.StaleHandle[0].Configs = make([]test_suite.ConfigItem, 1)
56+
cfg.StaleHandle[0].Configs = make([]test_suite.ConfigItem, 2)
5457
cfg.StaleHandle[0].Configs[0].Flags = []string{
55-
"--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc",
56-
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc",
58+
"--metadata-cache-ttl-secs=0 --enable-streaming-writes=false",
5759
}
5860
cfg.StaleHandle[0].Configs[0].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
61+
cfg.StaleHandle[0].Configs[0].Run = "TestStaleFileHandleLocalFileTest"
62+
cfg.StaleHandle[0].Configs[1].Flags = []string{
63+
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1",
64+
}
65+
cfg.StaleHandle[0].Configs[1].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
66+
cfg.StaleHandle[0].Configs[1].Run = "TestStaleFileHandleLocalFileTest"
5967
}
6068

69+
// Run all tests with GRPC.
70+
for i := range cfg.StaleHandle[0].Configs {
71+
// Create a temporary slice of slices to satisfy the function signature.
72+
tempFlags := [][]string{cfg.StaleHandle[0].Configs[i].Flags}
73+
setup.AppendFlagsToAllFlagsInTheFlagsSet(&tempFlags, "--client-protocol=grpc", "")
74+
cfg.StaleHandle[0].Configs[i].Flags = tempFlags[0]
75+
}
76+
77+
testEnv.cfg = &cfg.StaleHandle[0]
78+
testEnv.ctx = context.Background()
79+
testEnv.bucketType = setup.TestEnvironment(testEnv.ctx, testEnv.cfg)
80+
6181
// 2. Create storage client before running tests.
62-
ctx = context.Background()
63-
bucketType := setup.TestEnvironment(ctx, &cfg.StaleHandle[0])
64-
closeStorageClient := client.CreateStorageClientWithCancel(&ctx, &storageClient)
65-
defer func() {
66-
err := closeStorageClient()
67-
if err != nil {
68-
log.Fatalf("closeStorageClient failed: %v", err)
69-
}
70-
}()
82+
var err error
83+
testEnv.storageClient, err = client.CreateStorageClient(testEnv.ctx)
84+
if err != nil {
85+
log.Printf("Error creating storage client: %v\n", err)
86+
os.Exit(1)
87+
}
88+
defer testEnv.storageClient.Close()
7189

7290
// 3. To run mountedDirectory tests, we need both testBucket and mountedDirectory
73-
// flags to be set, as StaleHandle tests validates content from the bucket.
74-
if cfg.StaleHandle[0].GKEMountedDirectory != "" && cfg.StaleHandle[0].TestBucket != "" {
75-
os.Exit(setup.RunTestsForMountedDirectory(cfg.StaleHandle[0].GKEMountedDirectory, m))
91+
if testEnv.cfg.GKEMountedDirectory != "" && testEnv.cfg.TestBucket != "" {
92+
os.Exit(setup.RunTestsForMountedDirectory(testEnv.cfg.GKEMountedDirectory, m))
7693
}
7794

7895
// Run tests for testBucket
79-
// 4. Build the flag sets dynamically from the config.
80-
flags := setup.BuildFlagSets(cfg.StaleHandle[0], bucketType)
81-
82-
setup.SetUpTestDirForTestBucket(&cfg.StaleHandle[0])
96+
// Set up test directory.
97+
setup.SetUpTestDirForTestBucket(testEnv.cfg)
8398

84-
rootDir = setup.MntDir()
85-
successCode := static_mounting.RunTestsWithConfigFile(&cfg.StaleHandle[0], flags, m)
99+
log.Println("Running static mounting tests...")
100+
successCode := m.Run()
86101

102+
// Clean up test directory created.
103+
setup.CleanupDirectoryOnGCS(testEnv.ctx, testEnv.storageClient, testDirName)
87104
os.Exit(successCode)
88105
}

tools/integration_tests/stale_handle/stale_file_handle_common_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"cloud.google.com/go/storage"
2222
"github.com/googlecloudplatform/gcsfuse/v3/internal/util"
2323
. "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
24+
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/mounting/static_mounting"
2425
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations"
2526
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
2627
"github.com/stretchr/testify/assert"
@@ -33,11 +34,10 @@ import (
3334
// //////////////////////////////////////////////////////////////////////
3435

3536
type staleFileHandleCommon struct {
36-
flags []string
37+
flags [][]string
3738
f1 *os.File
3839
fileName string
3940
data string
40-
testDirPath string
4141
isStreamingWritesEnabled bool
4242
isLocal bool
4343
suite.Suite
@@ -47,14 +47,17 @@ type staleFileHandleCommon struct {
4747
// Helpers
4848
// //////////////////////////////////////////////////////////////////////
4949
func (s *staleFileHandleCommon) SetupSuite() {
50-
setup.MountGCSFuseWithGivenMountFunc(s.flags, mountFunc)
51-
s.testDirPath = setup.SetupTestDirectory(testDirName)
50+
s.flags = setup.BuildFlagSets(*testEnv.cfg, testEnv.bucketType, "TestStaleFileHandleLocalFileTest")
51+
}
52+
53+
func (s *staleFileHandleCommon) SetupTest() {
54+
setup.MountGCSFuseWithGivenMountWithConfigFunc(testEnv.cfg, s.flags[0], static_mounting.MountGcsfuseWithStaticMountingWithConfigFile)
55+
testEnv.testDirPath = SetupTestDirectory(testEnv.ctx, testEnv.storageClient, testDirName)
5256
s.data = setup.GenerateRandomString(5 * util.MiB)
5357
}
5458

55-
func (s *staleFileHandleCommon) TearDownSuite() {
56-
setup.UnmountGCSFuse(rootDir)
57-
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
59+
func (s *staleFileHandleCommon) TearDownTest() {
60+
setup.UnmountGCSFuseAndDeleteLogFile(setup.MntDir())
5861
}
5962

6063
////////////////////////////////////////////////////////////////////////
@@ -69,13 +72,13 @@ func (s *staleFileHandleCommon) TestClobberedFileSyncAndCloseThrowsStaleFileHand
6972
// Dirty the file by giving it some contents.
7073
operations.WriteWithoutClose(s.f1, s.data, s.T())
7174
// Clobber file by replacing the underlying object with a new generation.
72-
err := WriteToObject(ctx, storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
75+
err := WriteToObject(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
7376
assert.NoError(s.T(), err)
7477

7578
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
7679
err = s.f1.Close()
7780
operations.ValidateESTALEError(s.T(), err)
78-
ValidateObjectContentsFromGCS(ctx, storageClient, testDirName, s.fileName, FileContents, s.T())
81+
ValidateObjectContentsFromGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, FileContents, s.T())
7982
}
8083

8184
func (s *staleFileHandleCommon) TestFileDeletedLocallySyncAndCloseDoNotThrowError() {
@@ -91,7 +94,7 @@ func (s *staleFileHandleCommon) TestFileDeletedLocallySyncAndCloseDoNotThrowErro
9194
operations.WriteWithoutClose(s.f1, s.data, s.T())
9295
operations.SyncFile(s.f1, s.T())
9396
operations.CloseFileShouldNotThrowError(s.T(), s.f1)
94-
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, s.fileName, s.T())
97+
ValidateObjectNotFoundErrOnGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, s.T())
9598
}
9699

97100
func (s *staleFileHandleCommon) TestRenamedFileSyncAndCloseThrowsStaleFileHandleError() {
@@ -100,7 +103,7 @@ func (s *staleFileHandleCommon) TestRenamedFileSyncAndCloseThrowsStaleFileHandle
100103
assert.NoError(s.T(), err)
101104
newFile := "new" + s.fileName
102105

103-
err = operations.RenameFile(s.f1.Name(), path.Join(s.testDirPath, newFile))
106+
err = operations.RenameFile(s.f1.Name(), path.Join(testEnv.testDirPath, newFile))
104107

105108
assert.NoError(s.T(), err)
106109
_, err = s.f1.WriteString(s.data)

tools/integration_tests/stale_handle/stale_file_handle_local_file_test.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,28 @@ import (
2929
// Boilerplate
3030
// //////////////////////////////////////////////////////////////////////
3131

32-
type staleFileHandleLocalFile struct {
32+
type staleFileHandleLocalFileTest struct {
3333
staleFileHandleCommon
3434
}
3535

3636
// //////////////////////////////////////////////////////////////////////
3737
// Helpers
3838
// //////////////////////////////////////////////////////////////////////
3939

40-
func (s *staleFileHandleLocalFile) SetupTest() {
40+
func (s *staleFileHandleLocalFileTest) SetupTest() {
41+
s.staleFileHandleCommon.SetupTest()
4142
// Create a local file.
4243
s.fileName = path.Base(s.T().Name()) + setup.GenerateRandomString(5)
43-
s.f1 = operations.OpenFileWithODirect(s.T(), path.Join(s.testDirPath, s.fileName))
44+
s.f1 = operations.OpenFileWithODirect(s.T(), path.Join(testEnv.testDirPath, s.fileName))
4445
s.isLocal = true
46+
s.isStreamingWritesEnabled = !slices.Contains(s.flags[0], "--enable-streaming-writes=false")
4547
}
4648

4749
////////////////////////////////////////////////////////////////////////
4850
// Test Function (Runs once before all tests)
4951
////////////////////////////////////////////////////////////////////////
5052

5153
func TestStaleFileHandleLocalFileTest(t *testing.T) {
52-
// Run tests for mounted directory if the flag is set and return.
53-
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() {
54-
suite.Run(t, new(staleFileHandleLocalFile))
55-
return
56-
}
57-
for _, flags := range flagsSet {
58-
s := new(staleFileHandleLocalFile)
59-
s.flags = flags
60-
s.isStreamingWritesEnabled = !slices.Contains(s.flags, "--enable-streaming-writes=false")
61-
suite.Run(t, s)
62-
}
54+
suite.Run(t, new(staleFileHandleLocalFileTest))
6355
}
56+

tools/integration_tests/stale_handle/stale_file_handle_synced_file_test.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

118120
func 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
}

tools/integration_tests/test_config.yaml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,40 @@ requester_pays_bucket:
363363
hns: true
364364
zonal: false
365365

366-
367366
stale_handle:
368367
- mounted_directory: "${MOUNTED_DIR}"
369-
test_bucket: "${BUCKET_NAME}"
370-
log_file: # Optional
368+
test_bucket: "pranjal-bucket-1"
369+
log_file: # Not Required by stale_handle tests
371370
run_on_gke: false
372371
configs:
372+
# - flags:
373+
# - "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
374+
# - "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
375+
# compatible:
376+
# flat: true
377+
# hns: true
378+
# zonal: true
379+
# run: TestStaleFileHandleLocalFileTest
380+
381+
# stale_handle:
382+
# - mounted_directory: "${MOUNTED_DIR}"
383+
# test_bucket: "${BUCKET_NAME}"
384+
# log_file: # Not Required by stale_handle tests
385+
# run_on_gke: false
386+
# configs:
387+
- flags:
388+
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
389+
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
390+
compatible:
391+
flat: true
392+
hns: true
393+
zonal: true
394+
run: TestStaleFileHandleLocalFileTest
373395
- flags:
374-
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
375-
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
396+
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
397+
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
376398
compatible:
377399
flat: true
378400
hns: true
379401
zonal: true
402+
run: TestStaleFileHandleEmptyGcsFileTest

0 commit comments

Comments
 (0)