[test-improver] Improve tests for server session package#2989
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] Improve tests for server session package#2989github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Add tests for four previously-untested methods in session.go: - getSessionID: verifies it delegates correctly to SessionIDFromContext - ensureSessionDirectory: verifies it creates per-session dirs under payloadDir - requireSession: verifies auto-creation, deduplication, and concurrency safety - getSessionKeys: verifies correct enumeration of active session IDs Introduces a newMinimalUnifiedServer helper to reduce boilerplate in tests that need a real UnifiedServer instance. Co-authored-by: Copilot <[email protected]>
This was referenced Apr 1, 2026
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.
File Analyzed
internal/server/session_test.gointernal/serverImprovements Made
1. Increased Coverage
Four methods in
session.gohad zero test coverage. This PR adds tests for all of them:getSessionIDensureSessionDirectoryrequireSessiongetSessionKeys2. Better Testing Patterns
newMinimalUnifiedServerhelper witht.Helper()andt.Cleanup()to reduce boilerplate across testsrequire.NoErrorfor critical setup steps,assertfor non-fatal checkst.Run()with descriptive namest.TempDir()for filesystem isolation — no leftover state between runs3. Cleaner & More Stable Tests
UnifiedServer(or resetspayloadDir) so tests are fully independentrequireSessionverifies the double-checked locking ensures sessions are created exactly once under loadassert.Sameused to verify pointer identity (not just value equality) for session reuseKey New Tests
TestGetSessionID— confirmsgetSessionIDis a transparent wrapper forSessionIDFromContextacross absent, empty, non-string, and valid inputs.TestEnsureSessionDirectory— confirms the function createspayloadDir/sessionID/, is idempotent, and handles multiple sessions independently.TestRequireSession— confirms sessions are auto-created on first call, reused on subsequent calls, and that 20 concurrent goroutines all see the same single session instance.TestGetSessionKeys— confirms an empty server returns no keys, and that keys match exactly the set of sessions created viarequireSession.Why This File?
session.goimplements the session lifecycle for the gateway (creation, directory management, lookup). The existingsession_test.goonly tested the two pure functions (SessionIDFromContext,NewSession) and left the fourUnifiedServermethods completely uncovered. These methods contain non-trivial logic: directory creation,syncutil.GetOrCreatedouble-checked locking, and map iteration.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests