mirror of
https://github.com/redis/go-redis.git
synced 2025-12-02 06:22:31 +03:00
fix flaky test
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user