chore: add NewUnstartedHTTPServer helper to disable keep-alives on test servers - #28052
Draft
johnstcn wants to merge 4 commits into
Draft
chore: add NewUnstartedHTTPServer helper to disable keep-alives on test servers#28052johnstcn wants to merge 4 commits into
johnstcn wants to merge 4 commits into
Conversation
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)
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.
Adds
testutil.NewUnstartedHTTPServer, a known-good wrapper aroundhttptest.NewServerthat disables keep-alives by default, and refactors theaibridgeproxydhot-reload harness to use it.Why
Tests that proxy or pool connections to a bare
httptest.Serverintermittently 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, ownst.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)
WithKeepAlivesoption yet. The helper is intentionally minimal; aWithKeepAlivesfunctional option can be added when a test genuinely needs to exercise connection reuse.Verification
testutilandenterprise/aibridgeproxydsuites pass under-race.TestProxy_HotReloadRoutingandTestProxy_StaleTunnelpass 10x under-race.-race.Generated by a Coder agent.