Skip to content

Commit

Permalink
connpool: fix racy test (vitessio#14731)
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <[email protected]>
  • Loading branch information
vmg authored and ejortegau committed Dec 13, 2023
1 parent f27a574 commit d3750cd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions go/pools/smartconnpool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestOpen(t *testing.T) {
}

// Test that Get waits
ch := make(chan bool)
done := make(chan struct{})
go func() {
for i := 0; i < 5; i++ {
if i%2 == 0 {
Expand All @@ -163,14 +163,16 @@ func TestOpen(t *testing.T) {
for i := 0; i < 5; i++ {
p.put(resources[i])
}
ch <- true
close(done)
}()
for i := 0; i < 5; i++ {
// Sleep to ensure the goroutine waits
time.Sleep(10 * time.Millisecond)
// block until we have a client wait for a connection, then offer it
for p.wait.waiting() == 0 {
time.Sleep(time.Millisecond)
}
p.put(resources[i])
}
<-ch
<-done
assert.EqualValues(t, 5, p.Metrics.WaitCount())
assert.Equal(t, 5, len(state.waits))
// verify start times are monotonic increasing
Expand Down

0 comments on commit d3750cd

Please sign in to comment.