Skip to content

test(l4proxy): add unit tests for Handle (the proxy main loop)#435

Open
tannevaled wants to merge 1 commit into
mholt:masterfrom
tannevaled:test/handle-unit-tests
Open

test(l4proxy): add unit tests for Handle (the proxy main loop)#435
tannevaled wants to merge 1 commit into
mholt:masterfrom
tannevaled:test/handle-unit-tests

Conversation

@tannevaled

Copy link
Copy Markdown

What

Handler.Handle — the core proxy loop in modules/l4proxy — had no direct unit tests; its behavior was only exercised indirectly via integration tests. This PR adds focused unit tests that bring Handle to 100% statement coverage.

Tests added

Using the existing net.Pipe downstream pattern (already used by the dialPeers tests) plus a real loopback echo upstream:

  • No upstream available, no retry → returns no upstreams available.
  • Selected upstream unreachable, no retry → returns the dial error.
  • No upstream available, retry enabled → loops through tryAgain, then returns once TryDuration elapses.
  • Selected upstream unreachable, retry enabled → exercises the dial-failure retry/continue branch, then returns the error.
  • Success path → selects an upstream, dials it, proxies bytes in both directions, and returns nil after the downstream connection closes.

A small newHandleTestConn helper pairs an in-memory client end with a layer4.Connection wrapping the server end.

Verification

go test ./modules/l4proxy/ -race -run TestHandle   # all pass

Handle goes from 0% → 100% statement coverage. No production code changes.

Handle had no direct unit coverage; its behavior was only exercised
indirectly through integration tests. This adds focused unit tests using
the existing net.Pipe downstream pattern plus a real loopback echo
upstream, bringing Handle to 100% statement coverage:

- no upstream available + no retry -> returns 'no upstreams available'
- selected upstream unreachable + no retry -> returns the dial error
- no upstream available + retry enabled -> loops via tryAgain, then
  returns once TryDuration elapses
- selected upstream unreachable + retry enabled -> dial-failure retry
  loop, then returns the error
- success path -> selects, dials, proxies bytes both ways, returns nil
  after the downstream closes

All pass under -race.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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