Skip to content

Commit

Permalink
fix data race - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya1702 committed Jan 13, 2025
1 parent acbc8a0 commit 738c177
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/services/rpc_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"io"
"net/http"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -420,9 +419,7 @@ func TestTrackRPCServiceHealth_HealthyService(t *testing.T) {
}

func TestTrackRPCServiceHealth_UnhealthyService(t *testing.T) {
var logBuffer bytes.Buffer
log.DefaultLogger.SetOutput(&logBuffer)
defer log.DefaultLogger.SetOutput(os.Stderr)
getLogs := log.DefaultLogger.StartTest(log.WarnLevel)

mockHTTPClient := &utils.MockHTTPClient{}
rpcURL := "http://test-url-track-rpc-service-health"
Expand Down Expand Up @@ -450,8 +447,14 @@ func TestTrackRPCServiceHealth_UnhealthyService(t *testing.T) {
// Wait long enough for warning to trigger
time.Sleep(65 * time.Second)

logOutput := logBuffer.String()
assert.Contains(t, logOutput, "rpc service unhealthy for over 1m0s")
entries := getLogs()
testFailed := true
for _, entry := range entries {
if strings.Contains(entry.Message, "rpc service unhealthy for over 1m0s") {
testFailed = false
}
}
assert.False(t, testFailed)
mockHTTPClient.AssertExpectations(t)
}

Expand All @@ -465,9 +468,6 @@ func TestTrackRPCService_ContextCancelled(t *testing.T) {

go rpcService.TrackRPCServiceHealth(ctx)

// Cancel context immediately
cancel()

// Verify channel is closed after context cancellation
time.Sleep(100 * time.Millisecond)
_, ok := <-rpcService.GetHeartbeatChannel()
Expand Down

0 comments on commit 738c177

Please sign in to comment.