Repository navigation
test(etcdtest): share the embedded etcd and bind it to port 0 (#673, #509) - #678
Merged
Merged
Conversation
etcdtest replaces 4 embedded-etcd copies and 3 freeAddr copies. etcd binds its listeners to port 0, so the probe-then-bind race of #509 is gone. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KcLq1G8KpWBvM53JaQb1tS
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
8 tasks done
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.
Item 7 (etcd half) of #673. Also fixes #509's port race, by removing the race rather than retrying
around it.
A new
cluster/etcd/etcdtestpackage replaces the 4 embedded-etcd setups and the 3freeAddrcopies:cluster/etcdmembership and rejoin,cluster/router, and the rootcluster_test.gowith itsstartEtcd/tryStartEtcd/etcdStartAttempts. −31 lines net.API
Start(tb) string: the client endpoint.NewServer(tb) *Serverwith:Endpoint();Stop()(idempotent);Restart()(same client URL and data dir, for the rejoin test);Dial()(a client closed with the test).package etcd's internal tests can use it.#509: the race is gone by construction
The old helpers probed a free port, closed it, then handed the address to etcd, so another process
could take the port in between.
embed.StartEtcdcan't take a bound listener, but it doesaccept port 0.
etcdtestbinds both the client and peer URLs to127.0.0.1:0, and reads the realclient port from
e.Clients[0].Addr(). The kernel only ever hands out a free port, so there'snothing to retry.
Supporting changes:
:0. A single-node cluster never dials it.:0address, and clients don't use it.cluster/router's two HTTP test servers listen on127.0.0.1:0and read their address back,instead of probing with
freeAddr.Still exposed:
Server.Restartmust rebind its known port so running clients find etcd again. Thatwindow predates this PR and affects one test (
TestMembershipRejoinsAfterEtcdRestart).Relation to #513. #513 hardens probe-then-bind: it holds the listeners, retries 5×, and
classifies
EADDRINUSEby errno and message text. This PR removes probe-then-bind instead, so itsupersedes #513's first half. The two conflict in
cluster/etcd/membership_test.goandrejoin_test.go. #513's second half, which replaces theRejoins()assertion withSelfAbsent/memberKeyschecks, is independent and would rebase ontoetcdtest.Evidence
-count=20, before and after: cluster/etcd 680/680, cluster/router 320/320, root-run Cluster1220 passed / 20 skipped / 0 failed. No run logged "address already in use".
before or after. The old race is too narrow to reproduce on demand; this PR removes it by
construction.
go test ./...green.-raceon cluster/etcd, etcdtest and cluster/router green.-count=5oncluster/etcd and cluster/router green.
golangci-lint run --concurrency=2 ./...: 0 issues.cluster/ARCH.mdand theARCHITECTURE.mdpackage map are updated.The other half of item 7, a shared fetch-and-drain helper, is deliberately not in this PR. See #673.
🤖 Generated with Claude Code
https://claude.ai/code/session_01KcLq1G8KpWBvM53JaQb1tS