Skip to content

Conversation

@elboulangero
Copy link
Contributor

Otherwise when the test fails, the output is confusing, the expectation
is shown as "actual" and the other way round:

```
117s === RUN   TestLatency
117s     reply_test.go:273:
117s         	Error Trace:	/tmp/autopkgtest-lxc.v59pdptr/downtmp/autopkgtest_tmp/_build/src/github.com/gomodule/redigo/redis/reply_test.go:273
117s         	Error:      	Not equal:
117s         	            	expected: redis.Latency{Name:"command", Time:time.Date(2025, time.March, 11, 2, 49, 58, 0, time.Local), Latest:6000000, Max:6000000}
117s         	            	actual  : redis.Latency{Name:"command", Time:time.Date(2025, time.March, 11, 2, 49, 58, 0, time.Local), Latest:1000000, Max:1000000}
```
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)
```
Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for that.

@stevenh stevenh changed the title Fix latency tests (flaky) fix: latency tests Mar 15, 2025
@stevenh stevenh merged commit ad5af85 into gomodule:master Mar 15, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants