From d11bfcb8d417a3ba2d11ce5089c48f37f5371b5d Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Wed, 29 Jan 2025 12:46:23 -0500 Subject: [PATCH] Do not start goroutine in test (#121) --- internal/services/rpc_service_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/services/rpc_service_test.go b/internal/services/rpc_service_test.go index 5e36e09..ff9d3ef 100644 --- a/internal/services/rpc_service_test.go +++ b/internal/services/rpc_service_test.go @@ -442,10 +442,8 @@ func TestTrackRPCServiceHealth_UnhealthyService(t *testing.T) { mockHTTPClient.On("Post", rpcURL, "application/json", mock.Anything). Return(mockResponse, nil) - go rpcService.TrackRPCServiceHealth(ctx) - - // Wait long enough for warning to trigger - time.Sleep(65 * time.Second) + // The ctx will timeout after 70 seconds, which is enough for the warning to trigger + rpcService.TrackRPCServiceHealth(ctx) entries := getLogs() testFailed := true @@ -466,7 +464,7 @@ func TestTrackRPCService_ContextCancelled(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() - go rpcService.TrackRPCServiceHealth(ctx) + rpcService.TrackRPCServiceHealth(ctx) // Verify channel is closed after context cancellation time.Sleep(100 * time.Millisecond)