Skip to content

Commit a594d1c

Browse files
committed
stale file handle pckg update 23oct
1 parent ad84e02 commit a594d1c

File tree

5 files changed

+99
-114
lines changed

5 files changed

+99
-114
lines changed

tools/integration_tests/stale_handle/setup_test.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
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,
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
1514
package stale_handle
1615

1716
import (
@@ -22,6 +21,7 @@ import (
2221

2322
"cloud.google.com/go/storage"
2423
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
24+
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/mounting/static_mounting"
2525
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
2626
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/test_suite"
2727
)
@@ -31,7 +31,8 @@ const (
3131
)
3232

3333
var (
34-
testEnv env
34+
testEnv env
35+
mountFunc func(*test_suite.TestConfig, []string) error
3536
)
3637

3738
type env struct {
@@ -42,6 +43,10 @@ type env struct {
4243
bucketType string
4344
}
4445

46+
////////////////////////////////////////////////////////////////////////
47+
// TestMain
48+
////////////////////////////////////////////////////////////////////////
49+
4550
func TestMain(m *testing.M) {
4651
setup.ParseSetUpFlags()
4752

@@ -53,7 +58,8 @@ func TestMain(m *testing.M) {
5358
cfg.StaleHandle = make([]test_suite.TestConfig, 1)
5459
cfg.StaleHandle[0].TestBucket = setup.TestBucket()
5560
cfg.StaleHandle[0].GKEMountedDirectory = setup.MountedDirectory()
56-
cfg.StaleHandle[0].Configs = make([]test_suite.ConfigItem, 2)
61+
cfg.StaleHandle[0].LogFile = setup.LogFile()
62+
cfg.StaleHandle[0].Configs = make([]test_suite.ConfigItem, 4)
5763
cfg.StaleHandle[0].Configs[0].Flags = []string{
5864
"--metadata-cache-ttl-secs=0 --enable-streaming-writes=false",
5965
}
@@ -64,18 +70,20 @@ func TestMain(m *testing.M) {
6470
}
6571
cfg.StaleHandle[0].Configs[1].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
6672
cfg.StaleHandle[0].Configs[1].Run = "TestStaleFileHandleLocalFileTest"
73+
cfg.StaleHandle[0].Configs[2].Flags = []string{
74+
"--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{
79+
"--metadata-cache-ttl-secs=0 --write-block-size-mb=1 --write-max-blocks-per-file=1",
80+
}
81+
cfg.StaleHandle[0].Configs[3].Compatible = map[string]bool{"flat": true, "hns": true, "zonal": true}
82+
cfg.StaleHandle[0].Configs[3].Run = "TestStaleFileHandleSyncedFileTest"
6783
}
6884

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]
7885
testEnv.ctx = context.Background()
86+
testEnv.cfg = &cfg.StaleHandle[0]
7987
testEnv.bucketType = setup.TestEnvironment(testEnv.ctx, testEnv.cfg)
8088

8189
// 2. Create storage client before running tests.
@@ -88,18 +96,18 @@ func TestMain(m *testing.M) {
8896
defer testEnv.storageClient.Close()
8997

9098
// 3. To run mountedDirectory tests, we need both testBucket and mountedDirectory
99+
// flags to be set, as stale handle tests validates content from the bucket.
100+
// Note: These tests by default can only be run for non streaming mounts.
91101
if testEnv.cfg.GKEMountedDirectory != "" && testEnv.cfg.TestBucket != "" {
92102
os.Exit(setup.RunTestsForMountedDirectory(testEnv.cfg.GKEMountedDirectory, m))
93103
}
94104

95105
// Run tests for testBucket
96-
// Set up test directory.
97106
setup.SetUpTestDirForTestBucket(testEnv.cfg)
98107

99108
log.Println("Running static mounting tests...")
109+
mountFunc = static_mounting.MountGcsfuseWithStaticMountingWithConfigFile
100110
successCode := m.Run()
101111

102-
// Clean up test directory created.
103-
setup.CleanupDirectoryOnGCS(testEnv.ctx, testEnv.storageClient, testDirName)
104112
os.Exit(successCode)
105-
}
113+
}

tools/integration_tests/stale_handle/stale_file_handle_common_test.go

Lines changed: 13 additions & 15 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,
@@ -21,7 +21,6 @@ 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"
2524
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations"
2625
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
2726
"github.com/stretchr/testify/assert"
@@ -34,30 +33,23 @@ import (
3433
// //////////////////////////////////////////////////////////////////////
3534

3635
type staleFileHandleCommon struct {
37-
flags [][]string
36+
suite.Suite
37+
flags []string
3838
f1 *os.File
3939
fileName string
4040
data string
4141
isStreamingWritesEnabled bool
4242
isLocal bool
43-
suite.Suite
4443
}
4544

46-
// //////////////////////////////////////////////////////////////////////
47-
// Helpers
48-
// //////////////////////////////////////////////////////////////////////
4945
func (s *staleFileHandleCommon) SetupSuite() {
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)
46+
setup.MountGCSFuseWithGivenMountWithConfigFunc(testEnv.cfg, s.flags, mountFunc)
5547
testEnv.testDirPath = SetupTestDirectory(testEnv.ctx, testEnv.storageClient, testDirName)
5648
s.data = setup.GenerateRandomString(5 * util.MiB)
5749
}
5850

59-
func (s *staleFileHandleCommon) TearDownTest() {
60-
setup.UnmountGCSFuseAndDeleteLogFile(setup.MntDir())
51+
func (s *staleFileHandleCommon) TearDownSuite() {
52+
setup.UnmountGCSFuseWithConfig(testEnv.cfg)
6153
}
6254

6355
////////////////////////////////////////////////////////////////////////
@@ -75,7 +67,13 @@ func (s *staleFileHandleCommon) TestClobberedFileSyncAndCloseThrowsStaleFileHand
7567
err := WriteToObject(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
7668
assert.NoError(s.T(), err)
7769

78-
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
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+
}
76+
7977
err = s.f1.Close()
8078
operations.ValidateESTALEError(s.T(), err)
8179
ValidateObjectContentsFromGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, FileContents, s.T())

tools/integration_tests/stale_handle/stale_file_handle_local_file_test.go

Lines changed: 15 additions & 6 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,
@@ -20,9 +20,8 @@ import (
2020
"testing"
2121

2222
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations"
23-
"github.com/stretchr/testify/suite"
24-
2523
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
24+
"github.com/stretchr/testify/suite"
2625
)
2726

2827
// //////////////////////////////////////////////////////////////////////
@@ -38,18 +37,28 @@ type staleFileHandleLocalFileTest struct {
3837
// //////////////////////////////////////////////////////////////////////
3938

4039
func (s *staleFileHandleLocalFileTest) SetupTest() {
41-
s.staleFileHandleCommon.SetupTest()
4240
// Create a local file.
4341
s.fileName = path.Base(s.T().Name()) + setup.GenerateRandomString(5)
4442
s.f1 = operations.OpenFileWithODirect(s.T(), path.Join(testEnv.testDirPath, s.fileName))
4543
s.isLocal = true
46-
s.isStreamingWritesEnabled = !slices.Contains(s.flags[0], "--enable-streaming-writes=false")
4744
}
4845

4946
////////////////////////////////////////////////////////////////////////
5047
// Test Function (Runs once before all tests)
5148
////////////////////////////////////////////////////////////////////////
5249

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

tools/integration_tests/stale_handle/stale_file_handle_synced_file_test.go

Lines changed: 19 additions & 75 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,
@@ -19,104 +19,48 @@ import (
1919
"slices"
2020
"testing"
2121

22-
"cloud.google.com/go/storage"
23-
. "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
22+
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
2423
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations"
2524
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
26-
"github.com/stretchr/testify/assert"
2725
"github.com/stretchr/testify/suite"
2826
)
2927

3028
// //////////////////////////////////////////////////////////////////////
3129
// Boilerplate
3230
// //////////////////////////////////////////////////////////////////////
3331

34-
type staleFileHandleEmptyGcsFileTest struct {
32+
type staleFileHandleSyncedFileTest struct {
3533
staleFileHandleCommon
3634
}
3735

3836
// //////////////////////////////////////////////////////////////////////
3937
// Helpers
4038
// //////////////////////////////////////////////////////////////////////
4139

42-
func (s *staleFileHandleEmptyGcsFileTest) SetupTest() {
43-
s.staleFileHandleCommon.SetupTest()
44-
// Create an empty object on GCS.
40+
func (s *staleFileHandleSyncedFileTest) SetupTest() {
4541
s.fileName = path.Base(s.T().Name()) + setup.GenerateRandomString(5)
46-
err := CreateObjectOnGCS(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), "")
47-
assert.NoError(s.T(), err)
42+
// Create a file and sync it to GCS.
43+
client.SetupFileInTestDirectory(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, 1, s.T())
4844
s.f1 = operations.OpenFileWithODirect(s.T(), path.Join(testEnv.testDirPath, s.fileName))
49-
s.isStreamingWritesEnabled = !slices.Contains(s.flags[0], "--enable-streaming-writes=false")
45+
s.isLocal = false
5046
}
5147

5248
////////////////////////////////////////////////////////////////////////
53-
// Tests
49+
// Test Function (Runs once before all tests)
5450
////////////////////////////////////////////////////////////////////////
5551

56-
func (s *staleFileHandleEmptyGcsFileTest) TestClobberedFileReadThrowsStaleFileHandleError() {
57-
// TODO(b/410698332): Remove skip condition once takeover support is available.
58-
if s.isStreamingWritesEnabled && setup.IsZonalBucketRun() {
59-
s.T().Skip("Skip test due to takeover support not available.")
60-
}
61-
// Dirty the file by giving it some contents.
62-
_, err := s.f1.WriteAt([]byte(s.data), 0)
63-
assert.NoError(s.T(), err)
64-
operations.SyncFile(s.f1, s.T())
65-
66-
// Replace the underlying object with a new generation.
67-
err = WriteToObject(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
68-
69-
assert.NoError(s.T(), err)
70-
buffer := make([]byte, len(s.data))
71-
_, err = s.f1.Read(buffer)
72-
operations.ValidateESTALEError(s.T(), err)
73-
}
74-
75-
func (s *staleFileHandleEmptyGcsFileTest) TestClobberedFileFirstWriteThrowsStaleFileHandleError() {
76-
// TODO(b/410698332): Remove skip condition once takeover support is available.
77-
if s.isStreamingWritesEnabled && setup.IsZonalBucketRun() {
78-
s.T().Skip("Skip test due to takeover support not available.")
52+
func TestStaleFileHandleSyncedFileTest(t *testing.T) {
53+
// Run tests for mounted directory if the flag is set and return.
54+
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() {
55+
suite.Run(t, new(staleFileHandleSyncedFileTest))
56+
return
7957
}
80-
// Clobber file by replacing the underlying object with a new generation.
81-
err := WriteToObject(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName), FileContents, storage.Conditions{})
82-
assert.NoError(s.T(), err)
83-
84-
// Attempt first write to the file should give stale NFS file handle error.
85-
_, err = s.f1.Write([]byte(s.data))
86-
87-
assert.NoError(s.T(), err)
88-
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
89-
err = s.f1.Close()
90-
operations.ValidateESTALEError(s.T(), err)
91-
ValidateObjectContentsFromGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, FileContents, s.T())
92-
}
9358

94-
func (s *staleFileHandleEmptyGcsFileTest) TestFileDeletedRemotelySyncAndCloseThrowsStaleFileHandleError() {
95-
// TODO(mohitkyadav): Enable test once fix in b/415713332 is released
96-
if s.isStreamingWritesEnabled && setup.IsZonalBucketRun() {
97-
s.T().Skip("Skip test due to bug (b/415713332) in client.")
59+
flagsSet := setup.BuildFlagSets(*testEnv.cfg, testEnv.bucketType, t.Name())
60+
for _, flags := range flagsSet {
61+
s := new(staleFileHandleSyncedFileTest)
62+
s.flags = flags
63+
s.isStreamingWritesEnabled = !slices.Contains(s.flags, "--enable-streaming-writes=false")
64+
suite.Run(t, s)
9865
}
99-
// Dirty the file by giving it some contents.
100-
operations.WriteWithoutClose(s.f1, s.data, s.T())
101-
// Delete the file remotely.
102-
err := DeleteObjectOnGCS(testEnv.ctx, testEnv.storageClient, path.Join(testDirName, s.fileName))
103-
assert.NoError(s.T(), err)
104-
// Verify unlink operation succeeds.
105-
ValidateObjectNotFoundErrOnGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, s.T())
106-
// Attempt to write to file should not give any error.
107-
operations.WriteWithoutClose(s.f1, s.data, s.T())
108-
109-
operations.ValidateSyncGivenThatFileIsClobbered(s.T(), s.f1, s.isStreamingWritesEnabled)
110-
111-
err = s.f1.Close()
112-
operations.ValidateESTALEError(s.T(), err)
113-
ValidateObjectNotFoundErrOnGCS(testEnv.ctx, testEnv.storageClient, testDirName, s.fileName, s.T())
11466
}
115-
116-
////////////////////////////////////////////////////////////////////////
117-
// Test Function (Runs once before all tests)
118-
////////////////////////////////////////////////////////////////////////
119-
120-
func TestStaleFileHandleEmptyGcsFileTest(t *testing.T) {
121-
suite.Run(t, new(staleFileHandleEmptyGcsFileTest))
122-
}

0 commit comments

Comments
 (0)