Skip to content

[test-improver] Improve tests for launcher connection pool#7903

Merged
lpcox merged 2 commits into
mainfrom
test-improver/connection-pool-closed-state-5a38530f7d1038b2
Jun 22, 2026
Merged

[test-improver] Improve tests for launcher connection pool#7903
lpcox merged 2 commits into
mainfrom
test-improver/connection-pool-closed-state-5a38530f7d1038b2

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Improvements: connection_pool_test.go

File Analyzed

  • Test File: internal/launcher/connection_pool_test.go
  • Package: internal/launcher

Improvements Made

1. Increased Coverage

  • ✅ Added TestConnectionPoolGet_ClosedState: covers the ConnectionStateClosed early-exit branch in SessionConnectionPool.Get() (lines 232–235 of connection_pool.go)
Function Before After
SessionConnectionPool.Get 86.7% 100.0%
Package total 96.5% 97.0%

2. Cleaner & More Stable Tests

  • ✅ Follows the established direct-pool-manipulation pattern already used in TestCleanupIdleConnections_AlreadyClosedState — consistent with the rest of the file
  • ✅ Deterministic: no timers, goroutines, or external dependencies
  • ✅ Descriptive assertions with context messages

Test Execution

All tests pass:

=== RUN   TestConnectionPoolGet_ClosedState
--- PASS: TestConnectionPoolGet_ClosedState (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/launcher  17.124s  coverage: 97.0% of statements

Why These Changes?

SessionConnectionPool.Get() had an untested branch: when a connection exists in the pool map but its State is ConnectionStateClosed, Get returns (nil, false) without removing the entry. This is the correct behaviour (cleanup is delegated to cleanupIdleConnections), but the branch was never exercised by tests.

The new test injects a closed-state entry directly into pool.connections (same technique as TestCleanupIdleConnections_AlreadyClosedState) and asserts that Get correctly 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.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · 1.6K AIC · ⊞ 29.5K ·

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>
@lpcox lpcox marked this pull request as ready for review June 22, 2026 14:25
Copilot AI review requested due to automatic review settings June 22, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ClosedState to cover the ConnectionStateClosed branch in Get().
  • 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

Comment on lines +62 to +64
ctx := context.Background()
pool := NewSessionConnectionPool(ctx)
defer pool.Stop()
Comment on lines +69 to +76
pool.mu.Lock()
pool.connections[key] = &ConnectionMetadata{
Connection: &mcp.Connection{},
CreatedAt: time.Now(),
LastUsedAt: time.Now(),
State: ConnectionStateClosed,
}
pool.mu.Unlock()
@lpcox

lpcox commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed in c76521f.

Updates made in TestConnectionPoolGet_ClosedState:

  • switched to NewSessionConnectionPoolWithConfig with a long cleanup interval to keep the test deterministic
  • used a single now := time.Now() for both CreatedAt and LastUsedAt
  • changed lock usage to scoped defer pool.mu.Unlock() within a closure

Validation run: go test -v ./internal/launcher and make agent-finished both pass.

Copilot finished work on behalf of lpcox June 22, 2026 14:52
Copilot AI requested a review from lpcox June 22, 2026 14:52
@lpcox lpcox merged commit 08a643a into main Jun 22, 2026
26 checks passed
@lpcox lpcox deleted the test-improver/connection-pool-closed-state-5a38530f7d1038b2 branch June 22, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants