Skip to content

Commit 4a4237c

Browse files
committed
rebase and minor change
1 parent 59be6ff commit 4a4237c

6 files changed

Lines changed: 131 additions & 65 deletions

File tree

tools/integration_tests/stale_handle/setup_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,21 @@ func TestMain(m *testing.M) {
6262
cfg.StaleHandle[0].Configs = make([]test_suite.ConfigItem, 4)
6363
cfg.StaleHandle[0].Configs[0].Flags = []string{
6464
"--metadata-cache-ttl-secs=0 --enable-streaming-writes=false",
65+
"--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc",
66+
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1",
67+
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc",
6568
}
6669
cfg.StaleHandle[0].Configs[0].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
6770
cfg.StaleHandle[0].Configs[0].Run = "TestStaleFileHandleLocalFileTest"
71+
6872
cfg.StaleHandle[0].Configs[1].Flags = []string{
69-
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1",
70-
}
71-
cfg.StaleHandle[0].Configs[1].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
72-
cfg.StaleHandle[0].Configs[1].Run = "TestStaleFileHandleLocalFileTest"
73-
cfg.StaleHandle[0].Configs[2].Flags = []string{
7473
"--metadata-cache-ttl-secs=0 --enable-streaming-writes=false",
75-
}
76-
cfg.StaleHandle[0].Configs[2].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
77-
cfg.StaleHandle[0].Configs[2].Run = "TestStaleFileHandleSyncedFileTest"
78-
cfg.StaleHandle[0].Configs[3].Flags = []string{
74+
"--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc",
7975
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1",
76+
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc",
8077
}
81-
cfg.StaleHandle[0].Configs[3].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
82-
cfg.StaleHandle[0].Configs[3].Run = "TestStaleFileHandleSyncedFileTest"
78+
cfg.StaleHandle[0].Configs[1].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
79+
cfg.StaleHandle[0].Configs[1].Run = "TestStaleFileHandleEmptyGcsFileTest"
8380
}
8481

8582
testEnv.ctx = context.Background()

tools/integration_tests/stale_handle/stale_file_handle_common_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ func (s *staleFileHandleCommon) TestClobberedFileSyncAndCloseThrowsStaleFileHand
6767
err := WriteToObject(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
6868
assert.NoError(s.T(), err)
6969

70-
if s.isStreamingWritesEnabled && !s.isLocal {
71-
err = s.f1.Sync()
72-
operations.ValidateESTALEError(s.T(), err)
73-
} else {
74-
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
75-
}
70+
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
71+
// if s.isStreamingWritesEnabled && !s.isLocal {
72+
// err = s.f1.Sync()
73+
// operations.ValidateESTALEError(s.T(), err)
74+
// } else if !s.isLocal {
75+
// operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
76+
// }
7677

7778
err = s.f1.Close()
7879
operations.ValidateESTALEError(s.T(), err)

tools/integration_tests/stale_handle/stale_file_handle_local_file_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package stale_handle
1616

1717
import (
18+
"log"
1819
"path"
1920
"slices"
2021
"testing"
@@ -28,20 +29,23 @@ import (
2829
// Boilerplate
2930
// //////////////////////////////////////////////////////////////////////
3031

31-
type staleFileHandleLocalFileTest struct {
32+
type staleFileHandleLocalFile struct {
3233
staleFileHandleCommon
3334
}
3435

3536
// //////////////////////////////////////////////////////////////////////
3637
// Helpers
3738
// //////////////////////////////////////////////////////////////////////
3839

39-
func (s *staleFileHandleLocalFileTest) SetupTest() {
40+
func (s *staleFileHandleLocalFile) SetupTest() {
4041
// Create a local file.
4142
s.fileName = path.Base(s.T().Name()) + setup.GenerateRandomString(5)
4243
s.f1 = operations.OpenFileWithODirect(s.T(), path.Join(testEnv.testDirPath, s.fileName))
4344
s.isLocal = true
4445
}
46+
func (s *staleFileHandleLocalFile) TearDownTest() {
47+
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
48+
}
4549

4650
////////////////////////////////////////////////////////////////////////
4751
// Test Function (Runs once before all tests)
@@ -50,14 +54,15 @@ func (s *staleFileHandleLocalFileTest) SetupTest() {
5054
func TestStaleFileHandleLocalFileTest(t *testing.T) {
5155
// Run tests for mounted directory if the flag is set and return.
5256
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() {
53-
suite.Run(t, new(staleFileHandleLocalFileTest))
57+
suite.Run(t, new(staleFileHandleLocalFile))
5458
return
5559
}
5660

5761
flagsSet := setup.BuildFlagSets(*testEnv.cfg, testEnv.bucketType, t.Name())
5862
for _, flags := range flagsSet {
59-
s := new(staleFileHandleLocalFileTest)
63+
s := new(staleFileHandleLocalFile)
6064
s.flags = flags
65+
log.Printf("Running tests with flags: %s", s.flags)
6166
s.isStreamingWritesEnabled = !slices.Contains(s.flags, "--enable-streaming-writes=false")
6267
suite.Run(t, s)
6368
}

tools/integration_tests/stale_handle/stale_file_handle_synced_file_test.go

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
66
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
7+
// http://www.apache.org/licenses/LICENSE-2.0
88
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,51 +15,135 @@
1515
package stale_handle
1616

1717
import (
18+
"log"
1819
"path"
1920
"slices"
2021
"testing"
2122

23+
"cloud.google.com/go/storage"
2224
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
25+
. "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
2326
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations"
2427
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
28+
"github.com/stretchr/testify/assert"
2529
"github.com/stretchr/testify/suite"
2630
)
2731

2832
// //////////////////////////////////////////////////////////////////////
2933
// Boilerplate
3034
// //////////////////////////////////////////////////////////////////////
3135

32-
type staleFileHandleSyncedFileTest struct {
36+
type staleFileHandleEmptyGcsFile struct {
3337
staleFileHandleCommon
3438
}
3539

3640
// //////////////////////////////////////////////////////////////////////
3741
// Helpers
3842
// //////////////////////////////////////////////////////////////////////
3943

40-
func (s *staleFileHandleSyncedFileTest) SetupTest() {
44+
func (s *staleFileHandleEmptyGcsFile) SetupTest() {
4145
s.fileName = path.Base(s.T().Name()) + setup.GenerateRandomString(5)
4246
// Create a file and sync it to GCS.
4347
client.SetupFileInTestDirectory(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, 1, s.T())
4448
s.f1 = operations.OpenFileWithODirect(s.T(), path.Join(testEnv.testDirPath, s.fileName))
45-
s.isLocal = false
49+
// s.isLocal = false
50+
}
51+
func (s *staleFileHandleEmptyGcsFile) TearDownTest() {
52+
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
53+
}
54+
55+
////////////////////////////////////////////////////////////////////////
56+
// Tests
57+
////////////////////////////////////////////////////////////////////////
58+
59+
func (s *staleFileHandleEmptyGcsFile) TestClobberedFileReadThrowsStaleFileHandleError() {
60+
// TODO(b/410698332): Remove skip condition once takeover support is available.
61+
if s.isStreamingWritesEnabled && setup.IsZonalBucketRun() {
62+
s.T().Skip("Skip test due to takeover support not available.")
63+
}
64+
// Dirty the file by giving it some contents.
65+
_, err := s.f1.WriteAt([]byte(s.data), 0)
66+
assert.NoError(s.T(), err)
67+
operations.SyncFile(s.f1, s.T())
68+
69+
// Replace the underlying object with a new generation.
70+
err = WriteToObject(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
71+
72+
assert.NoError(s.T(), err)
73+
buffer := make([]byte, len(s.data))
74+
_, err = s.f1.Read(buffer)
75+
operations.ValidateESTALEError(s.T(), err)
76+
}
77+
78+
func (s *staleFileHandleEmptyGcsFile) TestClobberedFileFirstWriteThrowsStaleFileHandleError() {
79+
// TODO(b/410698332): Remove skip condition once takeover support is available.
80+
if s.isStreamingWritesEnabled && setup.IsZonalBucketRun() {
81+
s.T().Skip("Skip test due to takeover support not available.")
82+
}
83+
// Clobber file by replacing the underlying object with a new generation.
84+
err := WriteToObject(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
85+
assert.NoError(s.T(), err)
86+
87+
// Attempt first write to the file should give stale NFS file handle error.
88+
_, err = s.f1.Write([]byte(s.data))
89+
90+
assert.NoError(s.T(), err)
91+
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
92+
// if s.isStreamingWritesEnabled {
93+
// err = s.f1.Sync()
94+
// operations.ValidateESTALEError(s.T(), err)
95+
// } else {
96+
// operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
97+
// }
98+
err = s.f1.Close()
99+
operations.ValidateESTALEError(s.T(), err)
100+
ValidateObjectContentsFromGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, FileContents, s.T())
101+
}
102+
103+
func (s *staleFileHandleEmptyGcsFile) TestFileDeletedRemotelySyncAndCloseThrowsStaleFileHandleError() {
104+
// TODO(mohitkyadav): Enable test once fix in b/415713332 is released
105+
if s.isStreamingWritesEnabled && setup.IsZonalBucketRun() {
106+
s.T().Skip("Skip test due to bug (b/415713332) in client.")
107+
}
108+
// Dirty the file by giving it some contents.
109+
operations.WriteWithoutClose(s.f1, s.data, s.T())
110+
// Delete the file remotely.
111+
err := DeleteObjectOnGCS(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName))
112+
assert.NoError(s.T(), err)
113+
// Verify unlink operation succeeds.
114+
ValidateObjectNotFoundErrOnGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, s.T())
115+
// Attempt to write to file should not give any error.
116+
operations.WriteWithoutClose(s.f1, s.data, s.T())
117+
118+
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
119+
// if s.isStreamingWritesEnabled {
120+
// err = s.f1.Sync()
121+
// operations.ValidateESTALEError(s.T(), err)
122+
// } else {
123+
// operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
124+
// }
125+
126+
err = s.f1.Close()
127+
operations.ValidateESTALEError(s.T(), err)
128+
ValidateObjectNotFoundErrOnGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, s.T())
46129
}
47130

48131
////////////////////////////////////////////////////////////////////////
49132
// Test Function (Runs once before all tests)
50133
////////////////////////////////////////////////////////////////////////
51134

52-
func TestStaleFileHandleSyncedFileTest(t *testing.T) {
135+
func TestStaleFileHandleEmptyGcsFileTest(t *testing.T) {
53136
// Run tests for mounted directory if the flag is set and return.
54137
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() {
55-
suite.Run(t, new(staleFileHandleSyncedFileTest))
138+
suite.Run(t, new(staleFileHandleEmptyGcsFile))
56139
return
57140
}
58141

59142
flagsSet := setup.BuildFlagSets(*testEnv.cfg, testEnv.bucketType, t.Name())
60143
for _, flags := range flagsSet {
61-
s := new(staleFileHandleSyncedFileTest)
144+
s := new(staleFileHandleEmptyGcsFile)
62145
s.flags = flags
146+
log.Printf("Running tests with flags: %s", s.flags)
63147
s.isStreamingWritesEnabled = !slices.Contains(s.flags, "--enable-streaming-writes=false")
64148
suite.Run(t, s)
65149
}

tools/integration_tests/test_config.yaml

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -412,52 +412,31 @@ read_cache:
412412

413413
stale_handle:
414414
- mounted_directory: "${MOUNTED_DIR}"
415-
test_bucket: "pranjal-bucket-1"
416-
log_file: # Not Required by stale_handle tests
417-
run_on_gke: false
415+
test_bucket: "${BUCKET_NAME}"
418416
configs:
419417
- flags:
420-
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
421-
compatible:
422-
flat: true
423-
hns: true
424-
zonal: true
425-
run: TestStaleFileHandleLocalFileTest
426-
- flags:
427-
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
428-
compatible:
429-
flat: true
430-
hns: true
431-
zonal: true
432-
run: TestStaleFileHandleLocalFileTest
433-
- flags:
434-
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
435-
compatible:
436-
flat: true
437-
hns: true
438-
zonal: true
439-
run: TestStaleFileHandleEmptyGcsFileTest
440-
- flags:
441-
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
442-
compatible:
443-
flat: true
444-
hns: true
445-
zonal: true
446-
run: TestStaleFileHandleEmptyGcsFileTest
447-
- flags:
448-
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
418+
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false"
419+
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
420+
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1"
421+
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
449422
compatible:
450423
flat: true
451424
hns: true
452425
zonal: true
453-
run: TestStaleFileHandleSyncedFileTest
426+
run: "TestStaleFileHandleLocalFileTest"
427+
run_on_gke: true
454428
- flags:
455-
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
429+
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false"
430+
- "--metadata-cache-ttl-secs=0 --enable-streaming-writes=false --client-protocol=grpc"
431+
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1"
432+
- "--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1 --client-protocol=grpc"
456433
compatible:
457434
flat: true
458435
hns: true
459436
zonal: true
460-
run: TestStaleFileHandleSyncedFileTest
437+
run: "TestStaleFileHandleEmptyGcsFileTest"
438+
run_on_gke: true
439+
461440

462441
readdirplus:
463442
- mounted_directory: "${MOUNTED_DIR}"

tools/integration_tests/util/test_suite/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Config struct {
6464
ManagedFolders []TestConfig `yaml:"managed_folders"`
6565
ConcurrentOperations []TestConfig `yaml:"concurrent_operations"`
6666
Benchmarking []TestConfig `yaml:"benchmarking"`
67-
StaleHandle []TestConfig `yaml:"stale_handle"`
67+
StaleHandle []TestConfig `yaml:"stale_handle"`
6868
StreamingWrites []TestConfig `yaml:"streaming_writes"`
6969
InactiveStreamTimeout []TestConfig `yaml:"inactive_stream_timeout"`
7070
CloudProfiler []TestConfig `yaml:"cloud_profiler"`
@@ -106,7 +106,7 @@ func (c *Config) postProcessConfig() {
106106
processTestConfigs(c.ManagedFolders)
107107
processTestConfigs(c.ConcurrentOperations)
108108
processTestConfigs(c.Benchmarking)
109-
processTestConfigs(c.StaleHandles)
109+
processTestConfigs(c.StaleHandle)
110110
processTestConfigs(c.StreamingWrites)
111111
processTestConfigs(c.InactiveStreamTimeout)
112112
processTestConfigs(c.CloudProfiler)

0 commit comments

Comments
 (0)