Skip to content

net/http: port clientserver_test.go up to TestStarRequestMethod - #722

Merged
tamnd merged 5 commits into
mainfrom
clientserver
Oct 27, 2026
Merged

tamnd merged 5 commits into
mainfrom
clientserver

Conversation

@tamnd

@tamnd tamnd commented Oct 27, 2026

Copy link
Copy Markdown
Owner

What this is

This ports the first part of Go 1.27's net/http/clientserver_test.go: the shared harness plus every test from the top of the file down to TestStarRequestMethod. That's 33 tests, each running in h1 and h2 mode like Go's do. This is part of #6.

The harness is in tests/http_clientserver.h so that the serve, transport and client test ports can use it later. The tests are in tests/http_clientserver_test.c.

Go burrow
run, runSynctest run, run_synctest, with a RunOpts
newClientServerTest new_client_server_test, new_client_server_test_func
optFakeNet, optQuietLog, optWithServerLog and the server/transport funcs fields of CSTOpts
testMode and its Scheme TestMode, test_mode_string, test_mode_scheme
h12Compare, normalizeRes, mostlyCopy H12Compare, h12_normalize_res, mostly_equal

Not in Go

C has no closures and no garbage collector, so a few things work differently. Where the code departs from Go's, it has a "Not in Go" comment.

  • Test memory. test_alloc and test_arena hand out memory that lasts until the test's cleanups run. That covers state that Go's closures would keep alive.
  • Paused subtests. In short mode t.Parallel really pauses a subtest, and it carries on after testing_t_run has returned. So each mode's run state is allocated with test_alloc, not on the caller's stack.
  • No globals. Top-level tests that call t.Parallel run at the same time, so per-test state goes through an env pointer. For example, ReqFunc takes the test's env.
  • Handler memory. Handlers allocate from the request's arena, not from r->a, which is the heap.
  • TCP. Tests that need a real listener call cst_need_tcp. burrow only has TCP with the readiness poll FD, so the harness includes burrow/netpoll.h. Without it nearly every test skipped, which I caught on an early run.
  • No HTTP/3 mode. Go skips it for now too.

Tests

I ran these on server3 (Linux, clang) at 6a75265. The job builds http_clientserver_test and httptest_test three times: plain, with ASan+UBSan, and with TSan. It also runs the static checks first. The log, verbatim:

6a75265 net/http: allocate in the request's arena in the clientserver tests
ok tools/check-banned.sh
ok tools/check-headers.sh
ok tools/check-annotations.sh
ok tools/check-alloc.sh
ok tools/check-globals.sh
ok tools/check-statics.sh
ok tools/check-fips-module.sh
== build-cs6 make exit 0
http_clientserver_test exit 0: PASS
httptest_test exit 0: PASS
verbose exit 0: 69 PASS, 0 SKIP, 0 FAIL
== build-cs6a make exit 0
http_clientserver_test exit 0: PASS
httptest_test exit 0: PASS
== build-cs6t make exit 0
http_clientserver_test exit 0: PASS
httptest_test exit 0: PASS
count=5 http_clientserver_test exit 0: PASS
count=5 httptest_test exit 0: PASS
tsan count=5 #1 exit 0: PASS
tsan count=5 #2 exit 0: PASS
tsan count=5 #3 exit 0: PASS
all done

The "verbose" line counts the --- PASS, --- SKIP and --- FAIL lines from a -test.v -test.short run, so it includes the subtests. The two count=5 lines run the plain build with -test.short -test.count=5. The three tsan lines run the TSan build of http_clientserver_test with -test.count=5 and without -test.short.

What's next

The rest of clientserver_test.go, starting with TestTransportDiscardsUnneededConns.

tamnd added 5 commits October 27, 2026 22:26
Add tests/http_clientserver.h, the run, runSynctest and
newClientServerTest helpers from clientserver_test.go, and port the
tests from TestNewClientServerTest through the
TestH12_RequestContentLength tests.
…TestStarRequestMethod

Keep each mode's run state in test memory, since a subtest that pauses
in t.Parallel goes on after testing_t_run returns.
Without it BURROW_NETPOLL_READINESS is never defined there, and every
test that needs TCP skipped.
Pass a real Error to every write, since the server's writer stores
through it, and give the h12Compare request function the test's env in
place of globals that the parallel tests overwrote.
r->a is the allocator that made the request, which on the server is the
heap, so what the handlers made there leaked.
@tamnd tamnd added port Porting a standard library package, or part of one area: runtime Scheduler, goroutines, channels, select, defer, panic, netpoller labels Oct 27, 2026
@tamnd
tamnd merged commit a4b3f4b into main Oct 27, 2026
0 of 44 checks passed
@tamnd
tamnd deleted the clientserver branch October 27, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Scheduler, goroutines, channels, select, defer, panic, netpoller port Porting a standard library package, or part of one

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant