Skip to content

test: ⚡✅ Wait on events in forward proxy tests - #1984

Merged
evaline-ju merged 2 commits into
rossoctl:mainfrom
evaline-ju:no-time-tests-2-forwardproxy
Nov 19, 2026
Merged

evaline-ju merged 2 commits into
rossoctl:mainfrom
evaline-ju:no-time-tests-2-forwardproxy

Conversation

@evaline-ju

@evaline-ju evaline-ju commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removes timing from the forward proxy tests. Each test now waits for the event it checks, such as a store change, a handler being reached or a connection closing, instead of sleeping or polling to a deadline. Negative checks run right after a synchronous step, and expiry cases use a 1ns window. Timeouts that only guarded against hangs are gone, so a hang now fails with go test's goroutine dump.

The one production change is a seam in the tunnel's half-close drain: the drain takes its ticker as a parameter, so a test can send each tick itself. Production uses the same real ticker at the same interval.

Assisted-By: Claude (Anthropic AI)

Summary by CodeRabbit

  • Tests
    • Expanded checks across proxy tunnels, streaming responses, WebSocket connections, and session event recording.
    • Reworked test synchronization to wait for observable events and completion signals instead of relying on fixed delays and timeout-based polling.
    • Added controlled checks for tunnel draining and response streaming. These changes affect test coverage and reliability, not user-facing behavior.

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Forward proxy tests replace many timed waits, polling loops, and socket deadlines with event notifications, channel coordination, and direct reads. Tunnel-drain tests use injected ticks. Production tunnel draining retains its existing interval.

Changes: Forward proxy test synchronization

Layer / File(s) Summary
Wait for recorded events and outcomes
core/listener/forwardproxy/bridge_program_test.go, bridgedopen_test.go, bytescount_test.go, capture_test.go, egressguard_test.go, hopjoins_test.go, ingest_replay_test.go, process_test.go, project_test.go, redirect_test.go, session_affinity_test.go, tunnelreason_integration_test.go, upstreamfailure_test.go, translate_test.go
Tests use store notifications, recorder channels, and eventually to wait for session rows, captures, outcomes, and translation results.
Synchronize proxy, tunnel, and streaming tests
core/listener/forwardproxy/connect_hang_test.go, egress_test.go, hop_test.go, hopbyhop_test.go, mcp_sse_stream_test.go, misdirected_test.go, requestbodyfailure_test.go, server_test.go, skiphost_test.go, sniff_test.go, sse_relay_test.go, streaming_direction_test.go, streaming_test.go, tlsbridge_integration_test.go, transparent.go, transparent_test.go, truncated_stream_bridge_test.go, tunnelbehaviour_test.go, tunnelclose_test.go
Tests use explicit signals and reads instead of timed waits and socket deadlines. tunnel delegates to tunnelTicked, and drainTunnel accepts a ticker factory; the production factory uses time.NewTicker at the unchanged interval.
Coordinate WebSocket tests
core/listener/forwardproxy/websocket_review_test.go, websocket_test.go, websocketclose_test.go, websocketupgrade_test.go
Tests coordinate frame delivery and origin shutdown with channels. They use eventually to wait for session and upgrade rows.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Other

Suggested reviewers: huang195, mrsabath, clawgenti

Merge Risk: Minimal · up to 8099c

This change makes forward proxy tests wait on events rather than timers, and production tunnel behavior is unchanged. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: forward proxy tests now wait on events (store writes, handler arrival, connection close) instead of sleeping or polling against fixed deadlines. The summary confirms t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: forward proxy tests now wait on events (store writes, handler arrival, connection close) instead of sleeping or polling against fixed deadlines. The summary confirms this is the bulk of the changeset, which touches many forward proxy test files. The title also includes emoji shortcodes, which the title guidance asks to avoid. The emoji is noise but does not make the title misleading, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41fd62c6-df68-4a0e-9920-0c95da2b85ac
Commits

Reviewing files that changed from the base of the PR and between 53b70b9 and 8099c1b.

Files selected for processing: 4

  • core/listener/forwardproxy/egressguard_test.go
  • core/listener/forwardproxy/process_test.go
  • core/listener/forwardproxy/upgradedeclined_test.go
  • core/listener/forwardproxy/upstreamfailure_test.go
Files with no reviewable changes: 2

  • core/listener/forwardproxy/egressguard_test.go
  • core/listener/forwardproxy/upgradedeclined_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 19, 2026
@evaline-ju evaline-ju changed the title test: ✅ Wait on events in forward proxy tests test: ⚡✅ Wait on events in forward proxy tests Nov 19, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Test-only change apart from one behaviour-preserving seam in transparent.go (tunnel → tunnelTicked(..., newDrainTicker), same time.Ticker at the same halfCloseDrainVar/4 interval). I compared every removed assertion against its replacement and none were weakened; several are stronger (1h-ttl hop joins asserting nothing is left pending, waiting for the no-request connection to close instead of sleeping 50ms, ordering checks instead of a drip/2 bound, exact-length io.ReadFull reads). Every new wait registers its signal before checking its condition, so none can miss an event that fired first.

Stress on head (forwardproxy package): -count=20 and -race -count=20 both pass with 0 failures and 0 data races. One package run takes ~12s on head vs ~38s on base.

Advisory nits: the commit subject has no conventional prefix (test: is only in the PR title), and the PR body has a truncated sentence ("so tick.").

Author: evaline-ju (CONTRIBUTOR — repo admin permission; approved after manual confirmation)
Areas reviewed: Go tests, forward proxy listener
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing


// eventually blocks until cond holds, checking it again after each change to store. what
// names the awaited state, for the reader.
func eventually(t *testing.T, store *session.Store, cond func() bool, what string) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: what is no longer used, and with every timeout removed a regression now hangs until go test's 10-minute timeout panic. That uses 10 of the core CI job's 15 minutes and stops the rest of the package from running. Consider failing with what shortly before t.Deadline() (when set), e.g. t.Fatalf("timed out waiting for %s", what). Also worth documenting that cond is only re-checked when the store records something, so it must only depend on state that is set before a store write.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified the doc comment: cond is checked again after each store write, and
what names the awaited state. I'd rather not add a deadline-derived timer.
t.Deadline() is the deadline for the whole binary, so failing just before it
saves no CI time compared with go test's own timeout. It only changes the
message, and the timeout's goroutine dump already shows the blocked wait.
These tests wait on events throughout and leave hangs to go test's timeout.

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-reviewed at 8099c1b. The follow-up commit handles the points from the earlier review. The dead got == nil branches are gone, which is safe because outcomeRecorder.seen() only returns once done is closed, and done closes only when got is set. TestProcessAttribution_AConnectionWithNoRequestIsNotLookedUp now uses newProcessProxy with an http.Server hook rather than a copy that had drifted, and the hook runs before ts.Start(), so httptest's own ConnState wrapper still chains to it. eventually's doc comment now states what cond may depend on. Your reasoning for leaving hangs to go test's timeout (no CI time saved, and the goroutine dump shows where it is blocked) is fair, so I'm not pressing the deadline suggestion.

Ordering checks on head:

  • The store calls recorders under its write lock, after the event is applied, so a cond that reads through View sees the write that signalled it.
  • The non-store conditions (Programs/Skip/Unread) are updated in bridgeServe before tl.open writes the row, so those waits cannot miss their event.
  • bridgeServe runs synchronously inside HandleTransparentConn, so checking Skip after <-done1 is sound.
  • assertSplitsAt holds: sessionevent stamps At before it computes Duration, so At−Duration ≤ start.

Local runs of core/listener/forwardproxy on head: go vet is clean, -count=10 passes, and -race -count=10 shows no data races. One failure in the race run was TestEgress_DialFailure502WithKind (403 instead of 502), a test this PR doesn't touch. It reserves a port, closes it, and then newEgressRig opens new listeners, which can be handed that same port. It's a pre-existing flake and out of scope here, but it may be worth a follow-up given what this PR is about.

Still-open nits from the last pass (advisory): the PR body has a cut-off sentence ("so tick."), and the commit subjects have no conventional prefix.

Author: evaline-ju (CONTRIBUTOR, repo admin permission, so a maintainer)
Areas reviewed: Go tests and the forward-proxy listener (transparent.go drain-ticker seam, which keeps behaviour unchanged)
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed off: yes
CI status: passing

@evaline-ju
evaline-ju merged commit 9064cbe into rossoctl:main Nov 19, 2026
41 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 19, 2026
@evaline-ju
evaline-ju deleted the no-time-tests-2-forwardproxy branch November 19, 2026 15:37
huang195 added a commit that referenced this pull request Nov 19, 2026
PR #1984 added a store argument to the eventually test helper and
changed every caller that existed then. PR #1995 added parent_test.go
on a base without #1984, so its two calls use the old signature. Each
PR passed CI alone. After both merged, go vet on main fails:

  parent_test.go:146:24: not enough arguments in call to eventually

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
evaline-ju pushed a commit to evaline-ju/cortex that referenced this pull request Nov 19, 2026
… made without it

rossoctl#1984 (9064cbe) gave eventually a *session.Store parameter so it can
wait on the store's signal instead of sleeping. Two call sites in
parent_test.go, from 23ef75c, still called the three-argument form, so
go vet fails on main and every PR merging against it inherits the
failure. Both tests hold the store their rows come from; pass it.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Mariusz Sabath <mrsabath@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants