Fix flaky tests on Windows - #422
Open
bauerpawel wants to merge 1 commit into
Open
bauerpawel wants to merge 1 commit into
bauerpawel wants to merge 1 commit into
Conversation
Several tests failed intermittently on Windows: os.Remove on a file that still had an open handle, chmod-based permission tests that are no-ops on Windows, hardcoded "/"-separated path assertions, a wildcard-vs-specific address bind conflict, and testing/synctest's deterministic fake clock livelocking against real SQLite I/O contention under TestParallelDownloads (replaced with a plain sync.WaitGroup). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019woTYJGrS4pfPWC6CCgffQ
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Several tests in the suite fail intermittently (and in some cases deterministically) when run on Windows. Root causes:
os.Remove:generateHashAndEncrypt(internal/storage/FileServing.go) andgetDaysRemaining(internal/webserver/ssl/Ssl.go) didn't close a file handle before removing/rewriting that same file. On Linux this is a no-op; on Windows an open handle blocks the remove/rewrite, so the test either errors out or silently keeps stale data.Aws_test.gohad the same pattern.chmod-based permission tests:TestGetFileByChunkId(internal/storage/chunking/Chunking_test.go) usedos.Chmodto make a file read-only and assert a failing removal - POSIX permission bits are a no-op on Windows, so the assertion never held. Guarded withruntime.GOOS != "windows"./-separated path assertions:Localstorage_test.goasserted exact path strings using/, which don't matchfilepath-joined paths on Windows (\). Switched toos.PathSeparator.TestIsErrorAddressAlreadyInUse(Setup_test.go) bound a test listener to127.0.0.1:PORTbut the second server to:PORT(wildcard). On Windows, binding to the wildcard address doesn't reliably conflict with an existing listener bound to a specific address on the same port, so the intended "address already in use" error never surfaced. Now both bind to the same specific address.testing/synctestvs. real I/O contention:TestParallelDownloadsusedtesting/synctest's deterministic fake clock around 50 goroutines doing real SQLite writes. The fake clock has no way to gracefully coexist with unpredictable real-world I/O delays (e.g. antivirus briefly locking the database file) - a single external stall can look like a livelock, since retries governed by the fake clock spin far faster than the real delay actually resolves. Replaced with a plainsync.WaitGroup.None of these are behavior changes to production code paths except the two file-handle fixes, which are strictly more correct (closing a handle before removing/rewriting the same file) on every platform.
Type of Change
Technical Details
synctestlivelock (confirmed via goroutine dumps that the original, unmodified code also hung, ruling out a regression). I reviewed and tested all changes before submitting.How Has This Been Tested?
go test ./... --tags=test,awsmock(full suite passes, 15+ repeated runs of the previously-hangingTestParallelDownloads)Checklist
synctest→WaitGrouprationale, since it's non-obvious)🤖 Generated with Claude Code