Skip to content

Commit a7b2f91

Browse files
committed
flaky test
1 parent 5f0b58b commit a7b2f91

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

internal/pool/conn.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,9 @@ func (cn *Conn) MaybeHasData() bool {
902902
// Uses cached time to avoid expensive syscall (max 50ms staleness is acceptable for deadline calculation).
903903
func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time {
904904
// Use cached time for deadline calculation (called 2x per command: read + write)
905-
tm := time.Unix(0, getCachedTimeNs())
906-
cn.SetUsedAt(tm)
905+
nowNs := getCachedTimeNs()
906+
cn.SetUsedAtNs(nowNs)
907+
tm := time.Unix(0, nowNs)
907908

908909
if timeout > 0 {
909910
tm = tm.Add(timeout)

internal/pool/conn_used_at_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ func TestConn_UsedAtUpdatedOnWrite(t *testing.T) {
9191
// Verify the difference is reasonable (should be around 100ms, accounting for ~50ms cache precision)
9292
diff := updatedUsedAt.Sub(initialUsedAt)
9393

94-
if diff > 100*time.Millisecond {
95-
t.Errorf("Expected usedAt difference to be no more than 100ms (±50ms for cache), got %v", diff)
94+
// 50 ms is the cache precision, so we allow up to 110ms difference
95+
if diff < 45*time.Millisecond || diff > 155*time.Millisecond {
96+
t.Errorf("Expected usedAt difference to be around 100 (±50ms for cache) (+-5ms for sleep precision), got %v", diff)
9697
}
9798
}
9899

maintnotifications/pool_hook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func TestConnectionHook(t *testing.T) {
174174
select {
175175
case <-initConnCalled:
176176
// Good, initialization was called
177-
case <-time.After(1 * time.Second):
177+
case <-time.After(5 * time.Second):
178178
t.Fatal("Timeout waiting for initialization function to be called")
179179
}
180180

0 commit comments

Comments
 (0)