1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-02 06:22:31 +03:00

flaky test

This commit is contained in:
Nedyalko Dyakov
2025-10-30 18:48:33 +02:00
parent 5f0b58ba14
commit d207749af5
4 changed files with 9 additions and 7 deletions

View File

@@ -902,8 +902,9 @@ func (cn *Conn) MaybeHasData() bool {
// Uses cached time to avoid expensive syscall (max 50ms staleness is acceptable for deadline calculation). // 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 { func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time {
// Use cached time for deadline calculation (called 2x per command: read + write) // Use cached time for deadline calculation (called 2x per command: read + write)
tm := time.Unix(0, getCachedTimeNs()) nowNs := getCachedTimeNs()
cn.SetUsedAt(tm) cn.SetUsedAtNs(nowNs)
tm := time.Unix(0, nowNs)
if timeout > 0 { if timeout > 0 {
tm = tm.Add(timeout) tm = tm.Add(timeout)

View File

@@ -91,8 +91,9 @@ func TestConn_UsedAtUpdatedOnWrite(t *testing.T) {
// Verify the difference is reasonable (should be around 100ms, accounting for ~50ms cache precision) // Verify the difference is reasonable (should be around 100ms, accounting for ~50ms cache precision)
diff := updatedUsedAt.Sub(initialUsedAt) diff := updatedUsedAt.Sub(initialUsedAt)
if diff > 100*time.Millisecond { // 50 ms is the cache precision, so we allow up to 110ms difference
t.Errorf("Expected usedAt difference to be no more than 100ms (±50ms for cache), got %v", diff) 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)
} }
} }

View File

@@ -391,11 +391,11 @@ func TestPushNotifications(t *testing.T) {
go commandsRunner.FireCommandsUntilStop(ctx) go commandsRunner.FireCommandsUntilStop(ctx)
go commandsRunner2.FireCommandsUntilStop(ctx) go commandsRunner2.FireCommandsUntilStop(ctx)
go commandsRunner3.FireCommandsUntilStop(ctx) go commandsRunner3.FireCommandsUntilStop(ctx)
time.Sleep(30 * time.Second) time.Sleep(2 * time.Minute)
commandsRunner.Stop() commandsRunner.Stop()
commandsRunner2.Stop() commandsRunner2.Stop()
commandsRunner3.Stop() commandsRunner3.Stop()
time.Sleep(5 * time.Minute) time.Sleep(1 * time.Minute)
allLogsAnalysis := logCollector.GetAnalysis() allLogsAnalysis := logCollector.GetAnalysis()
trackerAnalysis := tracker.GetAnalysis() trackerAnalysis := tracker.GetAnalysis()

View File

@@ -174,7 +174,7 @@ func TestConnectionHook(t *testing.T) {
select { select {
case <-initConnCalled: case <-initConnCalled:
// Good, initialization was called // 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") t.Fatal("Timeout waiting for initialization function to be called")
} }