test(network/grpc): fix race in Test_grpcConnectionManager_Peers#4276
Open
stevenvegt wants to merge 1 commit into
Open
test(network/grpc): fix race in Test_grpcConnectionManager_Peers#4276stevenvegt wants to merge 1 commit into
stevenvegt wants to merge 1 commit into
Conversation
Contributor
|
Coverage Impact ⬇️ Merging this pull request will decrease total coverage on 🛟 Help
|
…g down Test_grpcConnectionManager_Peers/inbound_stream_triggers_observer and the mirror outbound subtest set Authenticate expectations on both peer's authenticator mocks but only waited for one side's observer to fire before calling cm2.Stop(). When the observed side won the race, the other side's authenticator could still be in flight when t.Cleanup ran gomock's Finish(), reporting a missing call. Extend the wait condition to also require the unobserved side's Peers() list to be populated, which only happens after that side's Authenticate returns. Assisted-by: AI
06c187b to
68bc22c
Compare
reinkrul
approved these changes
May 23, 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.

Problem
`Test_grpcConnectionManager_Peers/inbound_stream_triggers_observer` (and the mirror outbound subtest) is flaky on CI. Example failure: PR #4275, run 26294161548.
The failure message:
```
controller.go:97: missing call(s) to *grpc.MockAuthenticator.Authenticate(is equal to did:nuts:test (did.DID), is anything)
```
Root cause
Both subtests set up two peers (cm1 and cm2) with separate `MockAuthenticator` mocks, and expect `Authenticate` to be called on both:
```go
authenticator1.EXPECT().Authenticate(*nodeDID, gomock.Any()).Return(transport.Peer{ID: "1"}, nil)
authenticator2.EXPECT().Authenticate(*nodeDID, gomock.Any()).Return(transport.Peer{ID: "2"}, nil)
```
But the wait condition only watches one side's observer:
```go
test.WaitFor(t, func() (bool, error) {
return capturedPeer.Load() != nil, nil
}, time.Second*2, "waiting for peer 1 observers")
```
Both authentications happen in parallel on opposite ends of the bufconn. When the observed side wins the race, `cm2.Stop()` runs while the other side's `Authenticate` is still in flight, and `t.Cleanup` triggers gomock's `Finish()` before the mock call lands.
Fix
Extend the wait condition to also require the unobserved side's `Peers()` list to be non-empty. A side only adds a remote to its `Peers()` list after its own `Authenticate` returns, so this guarantees both expectations have been satisfied before teardown.
Test plan