[test-improver] Improve tests for launcher connection pool#7903
Conversation
Adds a test that exercises the ConnectionStateClosed early-exit path in SessionConnectionPool.Get() (connection_pool.go lines 232-235). Previously, Get() had 86.7% coverage. With this test, it reaches 100%. The test directly inserts a closed-state ConnectionMetadata into the pool map (same approach used by TestCleanupIdleConnections_AlreadyClosedState) and asserts that Get returns (nil, false) without removing the entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Improves unit test coverage and stability for SessionConnectionPool.Get() by adding a deterministic test that exercises the “closed connection entry” early-exit path.
Changes:
- Added
TestConnectionPoolGet_ClosedStateto cover theConnectionStateClosedbranch inGet(). - Asserts that
Get()returns(nil, false)and does not remove the closed entry (leaving cleanup to the idle cleanup path).
Show a summary per file
| File | Description |
|---|---|
| internal/launcher/connection_pool_test.go | Adds a new unit test to cover the “closed-state entry exists in map” branch in SessionConnectionPool.Get(). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
| ctx := context.Background() | ||
| pool := NewSessionConnectionPool(ctx) | ||
| defer pool.Stop() |
| pool.mu.Lock() | ||
| pool.connections[key] = &ConnectionMetadata{ | ||
| Connection: &mcp.Connection{}, | ||
| CreatedAt: time.Now(), | ||
| LastUsedAt: time.Now(), | ||
| State: ConnectionStateClosed, | ||
| } | ||
| pool.mu.Unlock() |
|
@copilot address review feedback |
Addressed in c76521f. Updates made in
Validation run: |
Test Improvements:
connection_pool_test.goFile Analyzed
internal/launcher/connection_pool_test.gointernal/launcherImprovements Made
1. Increased Coverage
TestConnectionPoolGet_ClosedState: covers theConnectionStateClosedearly-exit branch inSessionConnectionPool.Get()(lines 232–235 ofconnection_pool.go)SessionConnectionPool.Get2. Cleaner & More Stable Tests
TestCleanupIdleConnections_AlreadyClosedState— consistent with the rest of the fileTest Execution
All tests pass:
Why These Changes?
SessionConnectionPool.Get()had an untested branch: when a connection exists in the pool map but itsStateisConnectionStateClosed,Getreturns(nil, false)without removing the entry. This is the correct behaviour (cleanup is delegated tocleanupIdleConnections), but the branch was never exercised by tests.The new test injects a closed-state entry directly into
pool.connections(same technique asTestCleanupIdleConnections_AlreadyClosedState) and asserts thatGetcorrectly signals "not found" while leaving the entry intact for the background cleanup pass.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.