From: Arnaud Rebillout <arnaudr@kali.org>
Date: Wed, 12 Mar 2025 09:45:57 +0700
Subject: fix: actual latency might be longer than expected

There's no guarantee that the latency will be 1ms exactly, it might be
longer, especially if the tests run on a busy machine.

This was spotted in the Debian automatic testing infrastructure:

```
 70s === RUN   TestLatency
 70s     reply_test.go:273:
 70s         	Error Trace:	/tmp/autopkgtest-lxc.slqiy8xs/downtmp/autopkgtest_tmp/_build/src/github.com/gomodule/redigo/redis/reply_test.go:273
 70s         	Error:      	Not equal:
 70s         	            	expected: redis.Latency{Name:"command", Time:time.Date(2025, time.March, 10, 22, 8, 39, 0, time.Local), Latest:2000000, Max:2000000}
 70s         	            	actual  : redis.Latency{Name:"command", Time:time.Date(2025, time.March, 10, 22, 8, 39, 0, time.Local), Latest:1000000, Max:1000000}
 70s
 70s         	            	Diff:
 70s         	            	--- Expected
 70s         	            	+++ Actual
 70s         	            	@@ -15,4 +15,4 @@
 70s         	            	  },
 70s         	            	- Latest: (time.Duration) 2000000,
 70s         	            	- Max: (time.Duration) 2000000
 70s         	            	+ Latest: (time.Duration) 1000000,
 70s         	            	+ Max: (time.Duration) 1000000
 70s         	            	 }
 70s         	Test:       	TestLatency
 70s --- FAIL: TestLatency (0.00s)
 70s === RUN   TestLatencyHistories
 70s     reply_test.go:314:
 70s         	Error Trace:	/tmp/autopkgtest-lxc.slqiy8xs/downtmp/autopkgtest_tmp/_build/src/github.com/gomodule/redigo/redis/reply_test.go:314
 70s         	Error:      	Not equal:
 70s         	            	expected: 1ms
 70s         	            	actual  : 2ms
 70s         	Test:       	TestLatencyHistories
 70s --- FAIL: TestLatencyHistories (0.00s)
```

Forwarded: https://github.com/gomodule/redigo/pull/685
---
 redis/reply_test.go | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/redis/reply_test.go b/redis/reply_test.go
index 36e3367..3f1705b 100644
--- a/redis/reply_test.go
+++ b/redis/reply_test.go
@@ -264,10 +264,14 @@ func TestLatency(t *testing.T) {
 	require.Equal(t, 1, len(latestLatencies))
 
 	latencyEvent := latestLatencies[0]
+
+	// The actual latency might be longer than 1ms
+	require.GreaterOrEqual(t, latencyEvent.Latest, time.Millisecond)
+	require.GreaterOrEqual(t, latencyEvent.Max, time.Millisecond)
 	expected := redis.Latency{
 		Name:   "command",
-		Latest: time.Millisecond,
-		Max:    time.Millisecond,
+		Latest: latencyEvent.Latest,
+		Max:    latencyEvent.Max,
 		Time:   latencyEvent.Time,
 	}
 	require.Equal(t, expected, latencyEvent)
@@ -315,7 +319,8 @@ func TestLatencyHistories(t *testing.T) {
 
 	require.Len(t, latencyHistory, 1)
 	latencyEvent := latencyHistory[0]
-	require.Equal(t, time.Millisecond, latencyEvent.ExecutionTime)
+	// The actual latency might be longer than 1ms
+	require.GreaterOrEqual(t, latencyEvent.ExecutionTime, time.Millisecond)
 }
 
 // dial wraps DialDefaultServer() with a more suitable function name for examples.
