Skip to content

Commit

Permalink
Fix races in test
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Feb 3, 2025
1 parent e00df5f commit e0538b7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions go/pools/smartconnpool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
type TestState struct {
lastID, open, close, reset atomic.Int64
waits []time.Time
mu sync.Mutex

chaos struct {
delayConnect time.Duration
Expand All @@ -46,6 +47,8 @@ type TestState struct {
}

func (ts *TestState) LogWait(start time.Time) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.waits = append(ts.waits, start)
}

Expand Down Expand Up @@ -1138,12 +1141,10 @@ func TestGetSpike(t *testing.T) {
}).Open(newConnector(&state), nil)

var resources [10]*Pooled[*TestConn]
var r *Pooled[*TestConn]
var err error

// Ensure we have a pool with 5 available resources
for i := 0; i < 5; i++ {
r, err = p.Get(ctx, nil)
r, err := p.Get(ctx, nil)

require.NoError(t, err)
resources[i] = r
Expand Down Expand Up @@ -1176,7 +1177,7 @@ func TestGetSpike(t *testing.T) {

go func() {
defer wg.Done()
r, err = p.Get(ctx, nil)
r, err := p.Get(ctx, nil)
defer p.put(r)

if err != nil {
Expand Down

0 comments on commit e0538b7

Please sign in to comment.