-
Notifications
You must be signed in to change notification settings - Fork 2
test(fscache): add filesystem limits tests and benchmarks #18
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
d75f52a
test(fscache): add filesystem limits tests and benchmarks
bartventer ccde4ee
ci: add cross-platform testing in GitHub Actions workflow
bartventer dab8025
test(fscache): ensure os-specific path handling
bartventer 773d498
ci: restrict Codecov upload to Ubuntu environment only
bartventer b3ef329
refactor(tests): remove example functions and improve path handling i…
bartventer 4b8d5a8
test(store/acceptance): increase key length in benchmarks [skip ci]
bartventer 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
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,129 @@ | ||
| // Copyright (c) 2025 Bart Venter <bartventer@proton.me> | ||
| // | ||
| // 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 fscache | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "runtime" | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/bartventer/httpcache/internal/testutil" | ||
| ) | ||
|
|
||
| func Test_Issue16_LongURLFragmentation(t *testing.T) { | ||
| t.Attr("GOOS", runtime.GOOS) | ||
| t.Attr("GOARCH", runtime.GOARCH) | ||
| t.Attr("GOVERSION", runtime.Version()) | ||
|
|
||
| tempDir := t.TempDir() | ||
| cache, err := Open("test-fragmentation", WithBaseDir(tempDir)) | ||
| testutil.RequireNoError(t, err) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| urlLen int | ||
| expectOK bool | ||
| }{ | ||
| {"normal URL", 100, true}, | ||
| {"long URL (1KB)", 1024, true}, | ||
| {"very long URL (4KB)", 4096, true}, | ||
| {"extremely long URL (10KB)", 10240, true}, | ||
| { | ||
| // While Go's stdlib handles long paths via \\?\ prefix on Windows, | ||
| // extremely deep directory hierarchies (2844+ levels) may still hit | ||
| // practical filesystem or OS limits beyond just path length. | ||
| // See fixLongPath logic in os/path_windows.go (https://cs.opensource.google/go/go/+/refs/tags/go1.25.3:src/os/path_windows.go;l=100;drc=79b809afb325ae266497e21597f126a3e98a1ef7) | ||
| "massive URL (100KB)", | ||
| 102400, | ||
| runtime.GOOS != "windows", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Generate URL of specified length | ||
| url := "https://example.com/" + strings.Repeat( | ||
| "x", | ||
| tt.urlLen-len("https://example.com/"), | ||
| ) | ||
|
|
||
| // Get fragmentation details | ||
| filename := cache.fn.FileName(url) | ||
| depth := strings.Count(filename, string(os.PathSeparator)) | ||
| t.Attr("URLLength", strconv.Itoa(len(url))) | ||
| t.Attr("PathLength", strconv.Itoa(len(filename))) | ||
| t.Attr("DirectoryDepth", strconv.Itoa(depth)) | ||
|
|
||
| // Test round-trip: Set -> Get -> Delete | ||
| data := []byte("test data") | ||
| err := cache.Set(url, data) | ||
|
|
||
| if tt.expectOK { | ||
| testutil.RequireNoError(t, err) | ||
|
|
||
| retrieved, getErr := cache.Get(url) | ||
| testutil.RequireNoError(t, getErr) | ||
| testutil.AssertEqual(t, string(data), string(retrieved)) | ||
|
|
||
| setErr := cache.Delete(url) | ||
| testutil.RequireNoError(t, setErr) | ||
|
|
||
| t.Logf("Successfully handled %d byte URL", len(url)) | ||
| } else if err == nil { | ||
| t.Errorf("Expected error for %d byte URL, but got none", len(url)) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Benchmark_Issue16_LongURLs(b *testing.B) { | ||
| tempDir := b.TempDir() | ||
| cache, err := Open("bench-long-urls", WithBaseDir(tempDir)) | ||
| if err != nil { | ||
| b.Fatal(err) | ||
| } | ||
|
|
||
| urlLengths := []int{100, 1000, 10000, 50000} | ||
|
|
||
| for _, length := range urlLengths { | ||
| b.Run(fmt.Sprintf("url_length_%d", length), func(b *testing.B) { | ||
| url := "https://example.com/" + strings.Repeat("x", length-len("https://example.com/")) | ||
| data := []byte("benchmark data") | ||
|
|
||
| b.ResetTimer() | ||
| for i := 0; b.Loop(); i++ { | ||
| key := fmt.Sprintf("%s-%d", url, i) | ||
|
|
||
| err := cache.Set(key, data) | ||
| if err != nil { | ||
| b.Fatal(err) | ||
| } | ||
|
|
||
| _, err = cache.Get(key) | ||
| if err != nil { | ||
| b.Fatal(err) | ||
| } | ||
|
|
||
| err = cache.Delete(key) | ||
| if err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
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.