Skip to content

Commit

Permalink
feat: fix data race in the test
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Feb 19, 2025
1 parent 7c59e0b commit f5fdb7c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions go/vt/discovery/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -1490,10 +1491,10 @@ func TestConcurrentUpdates(t *testing.T) {
// Subscribe to the healthcheck
// Make the receiver keep track of the updates received.
ch := hc.Subscribe()
totalCount := 0
var totalCount atomic.Int32
go func() {
for range ch {
totalCount++
totalCount.Add(1)
// Simulate a somewhat slow consumer.
time.Sleep(100 * time.Millisecond)
}
Expand All @@ -1510,7 +1511,7 @@ func TestConcurrentUpdates(t *testing.T) {
hc.Unsubscribe(ch)
defer close(ch)
require.Eventuallyf(t, func() bool {
return totalUpdates == totalCount
return totalUpdates == int(totalCount.Load())
}, 5*time.Second, 100*time.Millisecond, "expected all updates to be processed")
}

Expand Down

0 comments on commit f5fdb7c

Please sign in to comment.