Skip to content

chore: add NewUnstartedHTTPServer helper to disable keep-alives on test servers - #28052

Draft
johnstcn wants to merge 4 commits into
mainfrom
cian/aigov-430-httpserver-helper
Draft

chore: add NewUnstartedHTTPServer helper to disable keep-alives on test servers#28052
johnstcn wants to merge 4 commits into
mainfrom
cian/aigov-430-httpserver-helper

Conversation

@johnstcn

Copy link
Copy Markdown
Member

Adds testutil.NewUnstartedHTTPServer, a known-good wrapper around httptest.NewServer that disables keep-alives by default, and refactors the aibridgeproxyd hot-reload harness to use it.

Why

Tests that proxy or pool connections to a bare httptest.Server intermittently fail on Windows with a bare EOF when a stale pooled connection is reused. net/http will not retry a non-replayable request (e.g. a POST) on a closed pooled connection, so forcing a fresh connection per request eliminates the failure class. This is the same mechanism fixed in #28016 (AIGOV-430 / internal#1564), now expressed as a reusable, behavior-preserving helper.

Changes

  • testutil/http_server.go: NewUnstartedHTTPServer(t, handler) unstarted, keep-alives disabled, owns t.Cleanup. Caller calls .Start().
  • testutil/http_server_test.go: unit test proving the server closes the connection after one response (the keep-alives-off contract).
  • enterprise/aibridgeproxyd/reload_test.go: refactor the harness's hand-rolled server to the helper. Same behavior (keep-alives off), less boilerplate.

Out of scope (deliberate)

  • No WithKeepAlives option yet. The helper is intentionally minimal; a WithKeepAlives functional option can be added when a test genuinely needs to exercise connection reuse.
  • No lint rule or broader migration. A forcing-function analyzer covering more packages, plus wider adoption, belongs in a separate follow-up. This lands the helper with one concrete consumer as a working example.

Verification

  • testutil and enterprise/aibridgeproxyd suites pass under -race.
  • TestProxy_HotReloadRouting and TestProxy_StaleTunnel pass 10x under -race.
  • New helper unit test passes under -race.

Generated by a Coder agent.

Introduce testutil.NewUnstartedHTTPServer, wrapping httptest.NewServer with
keep-alives disabled by default. Tests that proxy or pool connections to a
bare httptest.Server intermittently fail on Windows with a bare EOF when a
stale pooled connection is reused, because net/http does not retry a
non-replayable request on a closed pooled connection. Disabling keep-alives
forces a fresh connection per request.

Refactor the aibridgeproxyd hot-reload harness to use it in place of a
hand-rolled httptest.Server with SetKeepAlivesEnabled(false).

Refs coder/internal#1564 (AIGOV-430)
@linear-code

linear-code Bot commented Aug 12, 2026

Copy link
Copy Markdown

AIGOV-430

@johnstcn johnstcn self-assigned this Aug 12, 2026
@johnstcn johnstcn changed the title test(testutil): add NewUnstartedHTTPServer helper to disable keep-alives on test servers chore: add NewUnstartedHTTPServer helper to disable keep-alives on test servers Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant