Skip to content

test(amqp091): join connectionWatcher goroutines in test teardown#109

Open
miotte wants to merge 1 commit into
miotte-pr7from
miotte-pr9
Open

test(amqp091): join connectionWatcher goroutines in test teardown#109
miotte wants to merge 1 commit into
miotte-pr7from
miotte-pr9

Conversation

@miotte
Copy link
Copy Markdown
Contributor

@miotte miotte commented May 30, 2026

Fixes #108

Stacked on #102 (miotte-pr7), which makes clientDisconnect atomic — this branch's teardown calls Disconnect in ~45 tests, and that would otherwise reintroduce the #101 race. A fully clean -race run of the amqp091 reconnect tests also needs #104 (atomic bd.state). Verified on a branch combining the whole stack (see Test plan). Once #102 merges, retarget this PR to main.

Summary

  • Add a sync.WaitGroup to BrokerDetails so the connectionWatcher goroutine started by Connect is joinable (the only production change).
  • Add a stopWatcher test helper that disconnects a client and waits for its watcher to exit, and defer it in every Connect-based test so a watcher can no longer outlive its test and either race the package-level NewAmqpConn091 swap (read in connect()) or panic calling IsClosed() on a stale mock from its 30s fallback branch.
  • The helper skips the disconnect when the test already triggered one (guarding on clientDisconnect.Load()), so it can't block on a second shutdownChan send.

Test plan

Verified on a branch combining this change with the full race-fix stack (#82, #84, #97, #98, #102, #104):

  • go test -race -run "Test_Retry|Test_WaitForConnect|Test_connect_connecting_" -count=5 ./internal/provider/connectors/amqp091/... — 12/12 runs pass (was ~75% before this fix).
  • go test -race -run "Test_Retry|Test_WaitForConnect|Test_connect_connecting_|Test_StreamRetry|Test_Disconnect$|Test_SubscribeStream" -count=5 ./internal/provider/connectors/amqp091/... — 6/6 pass (was 0/8 + a 10-minute hang before).
  • go test -race -count=5 ./internal/provider/connectors/amqp091/... — 3/3 pass.
  • go test ./... -race — passes across all packages.
  • go vet ./internal/provider/connectors/amqp091/... and gofmt clean.

Add a sync.WaitGroup to BrokerDetails so the connectionWatcher goroutine
started by Connect is joinable, and a stopWatcher test helper that
disconnects a client and waits for its watcher to exit. Defer it in every
Connect-based test so a watcher can no longer outlive its test and either
race the package-level NewAmqpConn091 swap (read in connect()) or panic
calling IsClosed() on a stale mock from its 30s fallback branch.

Signed-off-by: Michael Otteni <MichaelGOtteni@gmail.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