-
Notifications
You must be signed in to change notification settings - Fork 508
test(kernel range reader): Adding integration tests for verifying reads and writes size #4894
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
6 commits
Select commit
Hold shift + click to select a range
77d6516
Using already defined constant for MiB
abhishek10004 106ad2e
Integration tests to verify max_pages & max_write behavior
abhishek10004 cbf5fa5
Merge branch 'v3.11.1_release' of github.com:GoogleCloudPlatform/gcsf…
abhishek10004 5617454
Minor improvements
abhishek10004 ce331e8
Making fuse-max-request-size-kb flag conditional on enable-kernel-reader
abhishek10004 933804b
nit change
abhishek10004 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
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
107 changes: 107 additions & 0 deletions
107
tools/integration_tests/flag_optimizations/max_request_size_read_test.go
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,107 @@ | ||
| // Copyright 2026 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 flag_optimizations | ||
|
|
||
| import ( | ||
| "log" | ||
| "os" | ||
| "path" | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations" | ||
| "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| const ( | ||
| sixteenMiB = 16 * operations.MiB | ||
| sixteenMiBInBytes = "16777216" | ||
| ) | ||
|
|
||
| type MaxRequestSizeReadSuite struct { | ||
| suite.Suite | ||
| flags []string | ||
| } | ||
|
|
||
| func (s *MaxRequestSizeReadSuite) SetupSuite() { | ||
| mustMountGCSFuseAndSetupTestDir(s.flags, testEnv.ctx, testEnv.storageClient) | ||
| } | ||
|
|
||
| func (s *MaxRequestSizeReadSuite) TearDownSuite() { | ||
| tearDownOptimizationTest(s.T()) | ||
| } | ||
|
|
||
| func (s *MaxRequestSizeReadSuite) TestKernelReaderLargeRead16MiB() { | ||
| // 1. Check if the host kernel supports elevating max_pages limit to what is needed for a 16 MiB read. | ||
| requiredPages := sixteenMiB / os.Getpagesize() | ||
| data, err := os.ReadFile("/proc/sys/fs/fuse/max_pages_limit") | ||
| if err != nil { | ||
| s.T().Skipf("Skipping TestKernelReaderLargeRead16MiB: kernel does not support elevating max_pages limit (/proc/sys/fs/fuse/max_pages_limit: %v)", err) | ||
| } | ||
| if limit, err := strconv.Atoi(strings.TrimSpace(string(data))); err != nil || limit < requiredPages { | ||
| s.T().Skipf("Skipping TestKernelReaderLargeRead16MiB: /proc/sys/fs/fuse/max_pages_limit (%s, err: %v) is less than required %d pages for 16 MiB read (page size %d bytes)", strings.TrimSpace(string(data)), err, requiredPages, os.Getpagesize()) | ||
| } | ||
|
|
||
| // 2. Create 16 MiB test file in GCS. | ||
| testName := strings.ReplaceAll(s.T().Name(), "/", "_") | ||
| fileName := path.Join(testEnv.testDirPath, testName+"_16MiB.txt") | ||
| operations.CreateFileOfSize(sixteenMiB, fileName, s.T()) | ||
| s.T().Cleanup(func() { | ||
| _ = os.Remove(fileName) | ||
| }) | ||
|
|
||
| // 3. Truncate log file to record only the read operation. | ||
| err = os.Truncate(setup.LogFile(), 0) | ||
| require.NoError(s.T(), err, "Failed to truncate log file") | ||
|
|
||
| // 4. Perform a 16 MiB read. | ||
| content, err := os.ReadFile(fileName) | ||
| require.NoError(s.T(), err, "Failed to read 16 MiB file") | ||
| require.Len(s.T(), content, sixteenMiB) | ||
|
|
||
| // 5. Verify in gcsfuse trace log that exactly 1 read request of 16 MiB (16777216 bytes) occurred. | ||
| logContent, err := os.ReadFile(setup.LogFile()) | ||
| require.NoError(s.T(), err, "Failed to read log file after read") | ||
|
|
||
| lines := strings.Split(string(logContent), "\n") | ||
| var readRequestCount int | ||
| for _, line := range lines { | ||
| if strings.Contains(line, readFileStartMsg) { | ||
| readRequestCount++ | ||
| assert.Contains(s.T(), line, sixteenMiBInBytes, "Expected read request to be 16 MiB (%s bytes), but got line: %s", sixteenMiBInBytes, line) | ||
| } | ||
| } | ||
| assert.Equal(s.T(), 1, readRequestCount, "Expected exactly 1 read request of 16 MiB when kernel reader and fuse max pages support are enabled, got %d", readRequestCount) | ||
| } | ||
|
|
||
| func TestKernelReaderLargeReadSuite(t *testing.T) { | ||
| if setup.IsDynamicMount(testEnv.mountDir, testEnv.rootDir) { | ||
| t.Skip("Skipping test for dynamic mounting") | ||
| } | ||
| flagsSet := setup.BuildFlagSets(testEnv.cfg, testEnv.bucketType, t.Name()) | ||
| for _, flags := range flagsSet { | ||
| t.Run(strings.Join(flags, "_"), func(t *testing.T) { | ||
| log.Printf("Running tests with flags: %s", flags) | ||
| s := &MaxRequestSizeReadSuite{ | ||
| flags: flags, | ||
| } | ||
| suite.Run(t, s) | ||
| }) | ||
| } | ||
| } |
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
80 changes: 80 additions & 0 deletions
80
tools/integration_tests/write_large_files/max_request_size_test.go
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,80 @@ | ||
| // Copyright 2026 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 write_large_files | ||
|
|
||
| import ( | ||
| "os" | ||
| "path" | ||
| "strings" | ||
| "syscall" | ||
| "testing" | ||
|
|
||
| "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations" | ||
| "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| const ( | ||
| writeFileStartMsg = "<- WriteFile" | ||
| sixteenMiB = 16 * operations.MiB | ||
| oneMiBInBytes = "1048576" | ||
| ) | ||
|
|
||
| func TestWriteMaxRequestSize16MiB(t *testing.T) { | ||
| logContent, err := os.ReadFile(setup.LogFile()) | ||
| require.NoError(t, err, "Failed to read log file") | ||
| if !strings.Contains(string(logContent), "--fuse-max-request-size-kb=16384") { | ||
| t.Skip("Skipping TestWriteMaxRequestSize16MiB: --fuse-max-request-size-kb=16384 is not set in the mount config") | ||
| } | ||
|
|
||
| // Setup test directory and target file. | ||
| writeDir := setup.SetupTestDirectory("dirForMaxRequestSizeWrite") | ||
| filePath := path.Join(writeDir, "16MiB_write_test_"+setup.GenerateRandomString(5)+".txt") | ||
|
|
||
| // Truncate the log file right before writing so only our write operations are logged. | ||
| err = os.Truncate(setup.LogFile(), 0) | ||
| require.NoError(t, err, "Failed to truncate log file") | ||
|
|
||
| // Generate 16 MiB of random data (memory-aligned to os.Getpagesize() for O_DIRECT write). | ||
| data, err := operations.GenerateRandomData(sixteenMiB) | ||
| require.NoError(t, err, "Failed to generate random data") | ||
|
|
||
| // Open file with O_DIRECT so writes go straight to FUSE without kernel page-cache buffering. | ||
| f, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|syscall.O_DIRECT, setup.FilePermission_0600) | ||
| require.NoError(t, err, "Failed to open file for direct write") | ||
|
|
||
| // Write 16 MiB in a single buffer call. | ||
| n, err := f.Write(data) | ||
| require.NoError(t, err, "Failed to write 16 MiB to file") | ||
| require.Equal(t, sixteenMiB, n) | ||
|
abhishek10004 marked this conversation as resolved.
|
||
|
|
||
| err = f.Close() | ||
| require.NoError(t, err, "Failed to close file") | ||
|
|
||
| // Read log content after write. | ||
| logContent, err = os.ReadFile(setup.LogFile()) | ||
| require.NoError(t, err, "Failed to read log file after write") | ||
|
|
||
| lines := strings.Split(string(logContent), "\n") | ||
| var writeRequestCount int | ||
| for _, line := range lines { | ||
| if strings.Contains(line, writeFileStartMsg) { | ||
| writeRequestCount++ | ||
| assert.Contains(t, line, oneMiBInBytes, "Expected write request to be 1 MiB (%s bytes), but got line: %s", oneMiBInBytes, line) | ||
| } | ||
| } | ||
| assert.Equal(t, 16, writeRequestCount, "Expected exactly 16 write requests of 1 MiB each for 16 MiB write, got %d", writeRequestCount) | ||
| } | ||
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.