From 18b46a1ca7f80844887ae1d7540e80349c12ae36 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Wed, 5 Nov 2025 21:35:20 +0200 Subject: [PATCH] fix flaky test --- internal/pool/conn_used_at_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/pool/conn_used_at_test.go b/internal/pool/conn_used_at_test.go index d6dd27a0..97194505 100644 --- a/internal/pool/conn_used_at_test.go +++ b/internal/pool/conn_used_at_test.go @@ -22,7 +22,7 @@ func TestConn_UsedAtUpdatedOnRead(t *testing.T) { // Get initial usedAt time initialUsedAt := cn.UsedAt() - // Wait at least 50ms to ensure time difference (usedAt has ~50ms precision from cached time) + // Wait 100ms to ensure time difference (usedAt has ~50ms precision from cached time) time.Sleep(100 * time.Millisecond) // Simulate a read operation by calling WithReader @@ -45,10 +45,10 @@ func TestConn_UsedAtUpdatedOnRead(t *testing.T) { initialUsedAt, updatedUsedAt) } - // Verify the difference is reasonable (should be around 50ms, accounting for ~50ms cache precision) + // Verify the difference is reasonable (should be around 100ms, accounting for ~50ms cache precision and ~5ms sleep precision) diff := updatedUsedAt.Sub(initialUsedAt) - if diff < 50*time.Millisecond || diff > 200*time.Millisecond { - t.Errorf("Expected usedAt difference to be around 50ms (±50ms for cache), got %v", diff) + if diff < 45*time.Millisecond || diff > 155*time.Millisecond { + t.Errorf("Expected usedAt difference to be around 100ms (±50ms for cache, ±5ms for sleep), got %v", diff) } }