test(network): ack NATS messages before signalling test completion - #4488
Merged
Conversation
TestNetwork_Reprocess called wg.Done() before msg.Ack(). Once Done released the test, its cleanup shut down the embedded NATS server, and the ack on the callback goroutine failed with "nats: connection closed" on slow CI runners. Also stop calling require inside NATS callback goroutines (FailNow must run on the test goroutine) and read the ack error in the events integration test under the mutex instead of through a shared variable. Assisted-by: AI
stevenvegt
requested review from
Dirklectisch,
JorisHeadease,
gerardsn,
reinkrul and
woutslakhorst
as code owners
September 9, 2026 06:55
Contributor
|
Coverage Impact This PR will not change total coverage. 🚦 See full report on Qlty Cloud »🛟 Help
|
reinkrul
approved these changes
Sep 9, 2026
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.

Fixes the flaky
TestNetwork_Reprocess(seen on #4487 and earlier on an unrelated feature branch in July).The message handler in the test called
wg.Done()beforemsg.Ack().Donereleases the test'swg.Wait(), the subtest returns, its cleanup shuts down the embedded NATS server, and only then does the callback goroutine send the ack over a closed connection:nats: connection closed. On a fast machine the ack usually wins that race, on a loaded CI runner it sometimes loses. The fix deferswg.Done()so the ack always precedes it.The other three NATS handlers in tests were checked for the same pattern. Two in
network_integration_test.goare safe because they ack while holding the mutex the test polls on. Theirrequire.NoErrorcalls are changed toassert.NoError, sincerequirecallsFailNow, which must run on the test goroutine. The one inevents/integration_test.gowrote the ack error into a variable shared with the test goroutine; it now uses a dedicated variable read under the mutex.Verified with
go test -race -count=5on the affected packages.Backport to V6.2: follows as a separate PR.