-
Notifications
You must be signed in to change notification settings - Fork 458
feat(dentry cache): Add integration tests for dentry cache #3562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dentry_cache | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"cloud.google.com/go/storage" | ||
|
||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/test_setup" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type notifierTest struct { | ||
flags []string | ||
} | ||
|
||
func (s *notifierTest) Setup(t *testing.T) { | ||
mountGCSFuseAndSetupTestDir(s.flags, testDirName) | ||
} | ||
|
||
func (s *notifierTest) Teardown(t *testing.T) { | ||
if setup.MountedDirectory() == "" { // Only unmount if not using a pre-mounted directory | ||
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(setup.TestBucket(), testDirName)) | ||
setup.UnmountGCSFuseAndDeleteLogFile(rootDir) | ||
} | ||
} | ||
|
||
func (s *notifierTest) TestWriteFileWithDentryCacheEnabled(t *testing.T) { | ||
// Create a file with initial content directly in GCS. | ||
filePath := path.Join(setup.MntDir(), testDirName, testFileName) | ||
client.SetupFileInTestDirectory(ctx, storageClient, testDirName, testFileName, initialContentSize, t) | ||
// Stat file to cache the entry | ||
_, err := os.Stat(filePath) | ||
require.Nil(t, err) | ||
// Modify the object on GCS. | ||
objectName := path.Join(testDirName, testFileName) | ||
smallContent, err := operations.GenerateRandomData(updatedContentSize) | ||
require.Nil(t, err) | ||
require.Nil(t, client.WriteToObject(ctx, storageClient, objectName, string(smallContent), storage.Conditions{})) | ||
|
||
// First Write File attempt. | ||
err = operations.WriteFile(filePath, "ShouldNotWrite") | ||
|
||
// First Write File attempt should fail because file has been clobbered. | ||
operations.ValidateESTALEError(t, err) | ||
// Second Write File attempt. | ||
err = operations.WriteFile(filePath, "ShouldWrite") | ||
// The notifier is triggered after the first write failure, invalidating the kernel cache entry. | ||
// Therefore, the second write succeeds even before the metadata cache TTL expires. | ||
assert.Nil(t, err) | ||
} | ||
|
||
func (s *notifierTest) TestReadFileWithDentryCacheEnabled(t *testing.T) { | ||
// Create a file with initial content directly in GCS. | ||
filePath := path.Join(setup.MntDir(), testDirName, testFileName) | ||
client.SetupFileInTestDirectory(ctx, storageClient, testDirName, testFileName, initialContentSize, t) | ||
// Stat file to cache the entry | ||
_, err := os.Stat(filePath) | ||
require.Nil(t, err) | ||
// Modify the object on GCS. | ||
objectName := path.Join(testDirName, testFileName) | ||
smallContent, err := operations.GenerateRandomData(updatedContentSize) | ||
require.Nil(t, err) | ||
require.Nil(t, client.WriteToObject(ctx, storageClient, objectName, string(smallContent), storage.Conditions{})) | ||
|
||
// First Read File attempt. | ||
_, err = operations.ReadFile(filePath) | ||
|
||
// First Read File attempt should fail because file has been clobbered. | ||
operations.ValidateESTALEError(t, err) | ||
// Second Read File attempt. | ||
_, err = operations.ReadFile(filePath) | ||
// The notifier is triggered after the first read failure, invalidating the kernel cache entry. | ||
// Therefore, the second read succeeds even before the metadata cache TTL expires. | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestNotifierTest(t *testing.T) { | ||
ts := ¬ifierTest{} | ||
|
||
// Run tests for mounted directory if the flag is set. | ||
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() { | ||
test_setup.RunTests(t, ts) | ||
return | ||
} | ||
|
||
// Setup flags and run tests. | ||
ts.flags = []string{"--implicit-dirs", "--experimental-enable-dentry-cache", "--metadata-cache-ttl-secs=1000"} | ||
log.Printf("Running tests with flags: %s", ts.flags) | ||
test_setup.RunTests(t, ts) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Provides integration tests for enabling dentry cache. | ||
package dentry_cache | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"cloud.google.com/go/storage" | ||
|
||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/mounting/static_mounting" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup" | ||
) | ||
|
||
const ( | ||
testDirName = "testDirForDentryCache" | ||
testFileName = "testFile" | ||
initialContentSize = 5 | ||
updatedContentSize = 10 | ||
) | ||
|
||
var ( | ||
storageClient *storage.Client | ||
ctx context.Context | ||
testDirPath string | ||
mountFunc func([]string) error | ||
// mount directory is where our tests run. | ||
mountDir string | ||
// root directory is the directory to be unmounted. | ||
rootDir string | ||
) | ||
|
||
func mountGCSFuseAndSetupTestDir(flags []string, testDirName string) { | ||
setup.MountGCSFuseWithGivenMountFunc(flags, mountFunc) | ||
setup.SetMntDir(mountDir) | ||
testDirPath = client.SetupTestDirectory(ctx, storageClient, testDirName) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
setup.ParseSetUpFlags() | ||
if setup.TestBucket() == "" { | ||
log.Print("--testbucket must be specified") | ||
os.Exit(1) | ||
} | ||
|
||
// Create common storage client to be used in test. | ||
ctx = context.Background() | ||
closeStorageClient := client.CreateStorageClientWithCancel(&ctx, &storageClient) | ||
defer func() { | ||
err := closeStorageClient() | ||
if err != nil { | ||
log.Fatalf("closeStorageClient failed: %v", err) | ||
} | ||
}() | ||
|
||
if setup.MountedDirectory() != "" { | ||
mountDir = setup.MountedDirectory() | ||
// Run tests for mounted directory if the flag is set. | ||
os.Exit(m.Run()) | ||
} | ||
// Else run tests for testBucket. | ||
// Set up test directory. | ||
setup.SetUpTestDirForTestBucketFlag() | ||
|
||
// Save mount and root directory variables. | ||
mountDir, rootDir = setup.MntDir(), setup.MntDir() | ||
|
||
log.Println("Running static mounting tests...") | ||
mountFunc = static_mounting.MountGcsfuseWithStaticMounting | ||
successCode := m.Run() | ||
|
||
os.Exit(successCode) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dentry_cache | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"cloud.google.com/go/storage" | ||
|
||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup" | ||
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/test_setup" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type statWithDentryCacheEnabledTest struct { | ||
flags []string | ||
} | ||
|
||
func (s *statWithDentryCacheEnabledTest) Setup(t *testing.T) { | ||
mountGCSFuseAndSetupTestDir(s.flags, testDirName) | ||
} | ||
|
||
func (s *statWithDentryCacheEnabledTest) Teardown(t *testing.T) { | ||
if setup.MountedDirectory() == "" { // Only unmount if not using a pre-mounted directory | ||
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(setup.TestBucket(), testDirName)) | ||
setup.UnmountGCSFuseAndDeleteLogFile(rootDir) | ||
} | ||
} | ||
|
||
func (s *statWithDentryCacheEnabledTest) TestStatWithDentryCacheEnabled(t *testing.T) { | ||
// Create a file with initial content directly in GCS. | ||
filePath := path.Join(setup.MntDir(), testDirName, testFileName) | ||
client.SetupFileInTestDirectory(ctx, storageClient, testDirName, testFileName, initialContentSize, t) | ||
// Stat file to cache the entry | ||
_, err := os.Stat(filePath) | ||
require.Nil(t, err) | ||
// Modify the object on GCS. | ||
objectName := path.Join(testDirName, testFileName) | ||
smallContent, err := operations.GenerateRandomData(updatedContentSize) | ||
require.Nil(t, err) | ||
require.Nil(t, client.WriteToObject(ctx, storageClient, objectName, string(smallContent), storage.Conditions{})) | ||
|
||
// Stat again, it should give old cached attributes. | ||
fileInfo, err := os.Stat(filePath) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, int64(initialContentSize), fileInfo.Size()) | ||
// Wait until entry expires in cache. | ||
time.Sleep(1100 * time.Millisecond) | ||
// Stat again, it should give updated attributes. | ||
fileInfo, err = os.Stat(filePath) | ||
assert.Nil(t, err) | ||
assert.Equal(t, int64(updatedContentSize), fileInfo.Size()) | ||
} | ||
|
||
func TestStatWithDentryCacheEnabledTest(t *testing.T) { | ||
ts := &statWithDentryCacheEnabledTest{} | ||
|
||
// Run tests for mounted directory if the flag is set. | ||
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() { | ||
test_setup.RunTests(t, ts) | ||
return | ||
} | ||
|
||
// Setup flags and run tests. | ||
ts.flags = []string{"--implicit-dirs", "--experimental-enable-dentry-cache", "--metadata-cache-ttl-secs=1"} | ||
log.Printf("Running tests with flags: %s", ts.flags) | ||
test_setup.RunTests(t, ts) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.