From d207749af5bbaea41dc9309effb09765f7b14455 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Thu, 30 Oct 2025 18:48:33 +0200 Subject: [PATCH] flaky test --- internal/pool/conn.go | 5 +++-- internal/pool/conn_used_at_test.go | 5 +++-- maintnotifications/e2e/scenario_push_notifications_test.go | 4 ++-- maintnotifications/pool_hook_test.go | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/pool/conn.go b/internal/pool/conn.go index ad846651..71e71a8d 100644 --- a/internal/pool/conn.go +++ b/internal/pool/conn.go @@ -902,8 +902,9 @@ func (cn *Conn) MaybeHasData() bool { // Uses cached time to avoid expensive syscall (max 50ms staleness is acceptable for deadline calculation). func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time { // Use cached time for deadline calculation (called 2x per command: read + write) - tm := time.Unix(0, getCachedTimeNs()) - cn.SetUsedAt(tm) + nowNs := getCachedTimeNs() + cn.SetUsedAtNs(nowNs) + tm := time.Unix(0, nowNs) if timeout > 0 { tm = tm.Add(timeout) diff --git a/internal/pool/conn_used_at_test.go b/internal/pool/conn_used_at_test.go index 8461d6d1..d6dd27a0 100644 --- a/internal/pool/conn_used_at_test.go +++ b/internal/pool/conn_used_at_test.go @@ -91,8 +91,9 @@ func TestConn_UsedAtUpdatedOnWrite(t *testing.T) { // Verify the difference is reasonable (should be around 100ms, accounting for ~50ms cache precision) diff := updatedUsedAt.Sub(initialUsedAt) - if diff > 100*time.Millisecond { - t.Errorf("Expected usedAt difference to be no more than 100ms (±50ms for cache), got %v", diff) + // 50 ms is the cache precision, so we allow up to 110ms difference + if diff < 45*time.Millisecond || diff > 155*time.Millisecond { + t.Errorf("Expected usedAt difference to be around 100 (±50ms for cache) (+-5ms for sleep precision), got %v", diff) } } diff --git a/maintnotifications/e2e/scenario_push_notifications_test.go b/maintnotifications/e2e/scenario_push_notifications_test.go index 28677fa5..99139860 100644 --- a/maintnotifications/e2e/scenario_push_notifications_test.go +++ b/maintnotifications/e2e/scenario_push_notifications_test.go @@ -391,11 +391,11 @@ func TestPushNotifications(t *testing.T) { go commandsRunner.FireCommandsUntilStop(ctx) go commandsRunner2.FireCommandsUntilStop(ctx) go commandsRunner3.FireCommandsUntilStop(ctx) - time.Sleep(30 * time.Second) + time.Sleep(2 * time.Minute) commandsRunner.Stop() commandsRunner2.Stop() commandsRunner3.Stop() - time.Sleep(5 * time.Minute) + time.Sleep(1 * time.Minute) allLogsAnalysis := logCollector.GetAnalysis() trackerAnalysis := tracker.GetAnalysis() diff --git a/maintnotifications/pool_hook_test.go b/maintnotifications/pool_hook_test.go index 41120af2..6ec61eed 100644 --- a/maintnotifications/pool_hook_test.go +++ b/maintnotifications/pool_hook_test.go @@ -174,7 +174,7 @@ func TestConnectionHook(t *testing.T) { select { case <-initConnCalled: // Good, initialization was called - case <-time.After(1 * time.Second): + case <-time.After(5 * time.Second): t.Fatal("Timeout waiting for initialization function to be called") }