From 68bc22c119fd160a8ccf1b140e539443dd53971f Mon Sep 17 00:00:00 2001 From: Steven van der Vegt Date: Fri, 22 May 2026 16:56:09 +0200 Subject: [PATCH] test(network/grpc): wait for both sides to authenticate before tearing 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 --- network/transport/grpc/connection_manager_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/network/transport/grpc/connection_manager_test.go b/network/transport/grpc/connection_manager_test.go index e9b1e56f7c..f5aa5e2144 100644 --- a/network/transport/grpc/connection_manager_test.go +++ b/network/transport/grpc/connection_manager_test.go @@ -493,7 +493,7 @@ func Test_grpcConnectionManager_Peers(t *testing.T) { }, time.Second*2, "waiting for peer 1 to connect") }) t.Run("outbound stream triggers observer", func(t *testing.T) { - _, authenticator1, _, listener := create(t) + cm1, authenticator1, _, listener := create(t) cm2, authenticator2, _, _ := create(t, withBufconnDialer(listener)) authenticator1.EXPECT().Authenticate(*nodeDID, gomock.Any()).Return(transport.Peer{ID: "1"}, nil) authenticator2.EXPECT().Authenticate(*nodeDID, gomock.Any()).Return(transport.Peer{ID: "2"}, nil) @@ -506,9 +506,11 @@ func Test_grpcConnectionManager_Peers(t *testing.T) { cm2.Connect("bufnet", *nodeDID, nil) + // Wait until both sides have authenticated, otherwise the mock controller may + // run Finish() before authenticator1 fires and report a missing call. test.WaitFor(t, func() (bool, error) { - return capturedPeer.Load() != nil, nil - }, time.Second*2, "waiting for peer 2 observers") + return capturedPeer.Load() != nil && len(cm1.Peers()) > 0, nil + }, time.Second*2, "waiting for both sides to authenticate") assert.Equal(t, transport.Peer{ID: "2"}, capturedPeer.Load()) assert.Equal(t, transport.StateConnected, capturedState.Load()) @@ -532,9 +534,11 @@ func Test_grpcConnectionManager_Peers(t *testing.T) { cm2.Connect("bufnet", *nodeDID, nil) + // Wait until both sides have authenticated, otherwise the mock controller may + // run Finish() before authenticator2 fires and report a missing call. test.WaitFor(t, func() (bool, error) { - return capturedPeer.Load() != nil, nil - }, time.Second*2, "waiting for peer 1 observers") + return capturedPeer.Load() != nil && len(cm2.Peers()) > 0, nil + }, time.Second*2, "waiting for both sides to authenticate") assert.Equal(t, transport.Peer{ID: "1"}, capturedPeer.Load()) assert.Equal(t, transport.StateConnected, capturedState.Load())