Skip to content

Commit bc03ad9

Browse files
jackcclaude
andcommitted
pgxpool: only assert the lower bound of the ShouldPing idle duration
TestPoolAcquireChecksIdleConnsWithShouldPing released a connection, slept 200ms, and then required the idle duration reported to ShouldPing to be within 100ms of the sleep. A loaded CI runner can delay the acquire well past the sleep, and the test failed with an idle duration of 317.5ms. Only the lower bound is meaningful, so assert that instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent d7d8279 commit bc03ad9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

pgxpool/pool_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,23 @@ func TestPoolAcquireChecksIdleConnsWithShouldPing(t *testing.T) {
235235
require.NoError(t, err)
236236
defer pool.Close()
237237

238+
const idleTime = 200 * time.Millisecond
239+
238240
c, err := pool.Acquire(ctx)
239241
require.NoError(t, err)
240242
c.Release()
241243

242-
time.Sleep(time.Millisecond * 200)
244+
time.Sleep(idleTime)
243245

244246
c, err = pool.Acquire(ctx)
245247
require.NoError(t, err)
246248
conn := c.Conn()
247249

248250
require.NotNil(t, shouldPingLastCalledWith)
249251
assert.Equal(t, conn, shouldPingLastCalledWith.Conn)
250-
assert.InDelta(t, time.Millisecond*200, shouldPingLastCalledWith.IdleDuration, float64(time.Millisecond*100))
252+
// Only the lower bound can be asserted. A busy machine can delay the acquire arbitrarily long after the sleep,
253+
// which made an upper bound assertion flaky in CI.
254+
assert.GreaterOrEqual(t, shouldPingLastCalledWith.IdleDuration, idleTime)
251255

252256
c.Release()
253257
}

0 commit comments

Comments
 (0)