Skip to content

Commit 6810ae4

Browse files
committed
fix type and unset usage
1 parent 89a59a7 commit 6810ae4

File tree

1 file changed

+66
-29
lines changed

1 file changed

+66
-29
lines changed

engine/access/rpc/connection/connection_test.go

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestProxyExecutionAPI(t *testing.T) {
9292
en.handler.
9393
On("Ping",
9494
testifymock.Anything,
95-
testifymock.AnythingOfType("*access.PingRequest")).
95+
testifymock.AnythingOfType("*execution.PingRequest")).
9696
Return(expected, nil)
9797

9898
// create the factory
@@ -203,7 +203,7 @@ func TestProxyExecutionAPIConnectionReuse(t *testing.T) {
203203
en.handler.
204204
On("Ping",
205205
testifymock.Anything,
206-
testifymock.AnythingOfType("*access.PingRequest")).
206+
testifymock.AnythingOfType("*execution.PingRequest")).
207207
Return(expected, nil)
208208

209209
// create the factory
@@ -269,7 +269,7 @@ func TestExecutionNodeClientTimeout(t *testing.T) {
269269
en.handler.
270270
On("Ping",
271271
testifymock.Anything,
272-
testifymock.AnythingOfType("*access.PingRequest")).
272+
testifymock.AnythingOfType("*execution.PingRequest")).
273273
After(timeout+time.Second).
274274
Return(resp, nil)
275275

@@ -566,9 +566,14 @@ func TestExecutionNodeClientClosedGracefully(t *testing.T) {
566566
req := &execution.PingRequest{}
567567
resp := &execution.PingResponse{}
568568
respSent := atomic.NewUint64(0)
569-
en.handler.On("Ping", testifymock.Anything, req).Run(func(_ testifymock.Arguments) {
570-
respSent.Inc()
571-
}).Return(resp, nil)
569+
en.handler.
570+
On("Ping",
571+
testifymock.Anything,
572+
testifymock.AnythingOfType("*execution.PingRequest")).
573+
Run(func(_ testifymock.Arguments) {
574+
respSent.Inc()
575+
}).
576+
Return(resp, nil)
572577

573578
// create the factory
574579
connectionFactory := new(ConnectionFactoryImpl)
@@ -656,14 +661,18 @@ func TestEvictingCacheClients(t *testing.T) {
656661
// Set up mock handlers for Ping and GetNetworkParameters
657662
pingReq := &access.PingRequest{}
658663
pingResp := &access.PingResponse{}
659-
cn.handler.On("Ping", testifymock.Anything, pingReq).Return(
660-
func(context.Context, *access.PingRequest) *access.PingResponse {
661-
close(startPing)
662-
<-returnFromPing // keeps request open until returnFromPing is closed
663-
return pingResp
664-
},
665-
func(context.Context, *access.PingRequest) error { return nil },
666-
)
664+
cn.handler.
665+
On("Ping",
666+
testifymock.Anything,
667+
testifymock.AnythingOfType("*access.PingRequest")).
668+
Return(
669+
func(context.Context, *access.PingRequest) *access.PingResponse {
670+
close(startPing)
671+
<-returnFromPing // keeps request open until returnFromPing is closed
672+
return pingResp
673+
},
674+
func(context.Context, *access.PingRequest) error { return nil },
675+
)
667676

668677
netReq := &access.GetNetworkParametersRequest{}
669678
netResp := &access.GetNetworkParametersResponse{}
@@ -789,7 +798,9 @@ func TestConcurrentConnections(t *testing.T) {
789798
requestCount := rapid.IntRange(50, 1000).Draw(tt, "r")
790799
responsesSent := atomic.NewInt32(0)
791800
en.handler.
792-
On("Ping", testifymock.Anything, req).
801+
On("Ping",
802+
testifymock.Anything,
803+
testifymock.AnythingOfType("*execution.PingRequest")).
793804
Return(func(_ context.Context, _ *execution.PingRequest) (*execution.PingResponse, error) {
794805
time.Sleep(getSleep() * time.Microsecond)
795806

@@ -932,7 +943,13 @@ func TestCircuitBreakerExecutionNode(t *testing.T) {
932943
ctx := context.Background()
933944

934945
// Set up the handler mock to not respond within the requestTimeout.
935-
en.handler.On("Ping", testifymock.Anything, req).After(2*requestTimeout).Return(resp, nil)
946+
en.handler.
947+
On("Ping",
948+
testifymock.Anything,
949+
testifymock.AnythingOfType("*execution.PingRequest")).
950+
After(2*requestTimeout).
951+
Return(resp, nil).
952+
Once()
936953

937954
// Call and measure the duration for the first invocation.
938955
duration, err := callAndMeasurePingDuration(ctx)
@@ -941,28 +958,35 @@ func TestCircuitBreakerExecutionNode(t *testing.T) {
941958

942959
// Call and measure the duration for the second invocation (circuit breaker state is now "Open").
943960
duration, err = callAndMeasurePingDuration(ctx)
944-
assert.Equal(t, gobreaker.ErrOpenState, err)
961+
assert.ErrorIs(t, err, gobreaker.ErrOpenState)
945962
assert.Greater(t, requestTimeout, duration)
946963

947-
// Reset the mock Ping for the next invocation to return response without delay
948-
en.handler.On("Ping", testifymock.Anything, req).Unset()
949-
en.handler.On("Ping", testifymock.Anything, req).Return(resp, nil)
964+
en.handler.
965+
On("Ping",
966+
testifymock.Anything,
967+
testifymock.AnythingOfType("*execution.PingRequest")).
968+
Return(resp, nil).
969+
Once()
950970

951971
// Wait until the circuit breaker transitions to the "HalfOpen" state.
952972
time.Sleep(circuitBreakerRestoreTimeout + (500 * time.Millisecond))
953973

954974
// Call and measure the duration for the third invocation (circuit breaker state is now "HalfOpen").
955975
duration, err = callAndMeasurePingDuration(ctx)
956976
assert.Greater(t, requestTimeout, duration)
957-
assert.Equal(t, nil, err)
977+
assert.NoError(t, err)
958978
})
959979

960980
for _, code := range successCodes {
961981
t.Run(fmt.Sprintf("test error %s treated as a success for circuit breaker ", code.String()), func(t *testing.T) {
962982
ctx := context.Background()
963983

964-
en.handler.On("Ping", testifymock.Anything, req).Unset()
965-
en.handler.On("Ping", testifymock.Anything, req).Return(nil, status.Error(code, code.String()))
984+
en.handler.
985+
On("Ping",
986+
testifymock.Anything,
987+
testifymock.AnythingOfType("*execution.PingRequest")).
988+
Return(nil, status.Error(code, code.String())).
989+
Once()
966990

967991
duration, err := callAndMeasurePingDuration(ctx)
968992
require.Error(t, err)
@@ -1038,7 +1062,13 @@ func TestCircuitBreakerCollectionNode(t *testing.T) {
10381062
ctx := context.Background()
10391063

10401064
// Set up the handler mock to not respond within the requestTimeout.
1041-
cn.handler.On("Ping", testifymock.Anything, req).After(2*requestTimeout).Return(resp, nil)
1065+
cn.handler.
1066+
On("Ping",
1067+
testifymock.Anything,
1068+
testifymock.AnythingOfType("*access.PingRequest")).
1069+
After(2*requestTimeout).
1070+
Return(resp, nil).
1071+
Once()
10421072

10431073
// Call and measure the duration for the first invocation.
10441074
duration, err := callAndMeasurePingDuration(ctx)
@@ -1050,9 +1080,12 @@ func TestCircuitBreakerCollectionNode(t *testing.T) {
10501080
assert.Equal(t, gobreaker.ErrOpenState, err)
10511081
assert.Greater(t, requestTimeout, duration)
10521082

1053-
// Reset the mock Ping for the next invocation to return response without delay
1054-
cn.handler.On("Ping", testifymock.Anything, req).Unset()
1055-
cn.handler.On("Ping", testifymock.Anything, req).Return(resp, nil)
1083+
cn.handler.
1084+
On("Ping",
1085+
testifymock.Anything,
1086+
testifymock.AnythingOfType("*access.PingRequest")).
1087+
Return(resp, nil).
1088+
Once()
10561089

10571090
// Wait until the circuit breaker transitions to the "HalfOpen" state.
10581091
time.Sleep(circuitBreakerRestoreTimeout + (500 * time.Millisecond))
@@ -1067,8 +1100,12 @@ func TestCircuitBreakerCollectionNode(t *testing.T) {
10671100
t.Run(fmt.Sprintf("test error %s treated as a success for circuit breaker ", code.String()), func(t *testing.T) {
10681101
ctx := context.Background()
10691102

1070-
cn.handler.On("Ping", testifymock.Anything, req).Unset()
1071-
cn.handler.On("Ping", testifymock.Anything, req).Return(nil, status.Error(code, code.String()))
1103+
cn.handler.
1104+
On("Ping",
1105+
testifymock.Anything,
1106+
testifymock.AnythingOfType("*access.PingRequest")).
1107+
Return(nil, status.Error(code, code.String())).
1108+
Once()
10721109

10731110
duration, err := callAndMeasurePingDuration(ctx)
10741111
require.Error(t, err)

0 commit comments

Comments
 (0)