refactor: extract Dialer interface to decouple proxy logic from tsnet#12
Merged
Conversation
Replace *tsnet.Server with Dialer interface in acceptLoop and handleConn, enabling mock-based testing of core proxy logic without a Tailscale network. tsnet.Server satisfies the interface implicitly — no adapter needed. Also fixes a pre-existing data race in proxyConnections where the rx goroutine could still be writing when the function returned byte counts.
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.
Summary
Dialerinterface (Dial(ctx, network, addr) → net.Conn) soacceptLoopandhandleConnno longer depend on*tsnet.Serverdirectlytsnet.Serversatisfies the interface implicitly — zero adapter code neededproxyConnectionswhere therxgoroutine could still write after the function returned byte counts (addedsync.WaitGroup)"closed pipe"to expected close errors (pipe analog of ECONNRESET)Changes
main.go: +6 linesDialerinterface, signature updates, WaitGroup fixmain_test.go: +3 new tests (TestDialerInterfaceSatisfaction,TestHandleConnWithDialer,TestAcceptLoopWithDialer)main_integration_test.go: +1 test case for closed pipe error classificationTesting
go test -race -count=5 ./...— 0 failures, 0 racesgo vet ./...cleango build ./...cleanType
refactor— Code restructuring (no behavior change)fix— Bug fix (proxyConnections race condition)ARCH-001 from Stream E roadmap. Enables ARCH-003 (mock-based proxy tests) and ARCH-004 (reconnection logic).