fix TestEmptyBuffer flakiness from timestamp collisions

TestEmptyBuffer added items without an explicit Message.Time, letting
Add() stamp them with time.Now().UTC(), then immediately queried with
end = time.Now() as the (exclusive) upper bound. On platforms where the
wall clock has coarse resolution -- macOS ticks in 1us increments, so
consecutive time.Now() calls usually return identical wall times -- the
item's timestamp equals the query bound, item.Message.Time.Before(before)
is false, and the item is excluded. The test then panics indexing the
empty result slice.

On Apple Silicon this fails nearly deterministically; Linux's
nanosecond-resolution clock is why CI never caught it.

Use explicit fixed timestamps via easyItem, matching every other test
in this file.
This commit is contained in:
Matt Ouille
2026-07-07 16:57:20 -07:00
parent 510687981a
commit d47d7a8bdf
+3 -9
View File
@@ -24,9 +24,7 @@ func TestEmptyBuffer(t *testing.T) {
buf := NewHistoryBuffer(0, 0)
buf.Add(Item{
Nick: "testnick",
})
buf.Add(easyItem("testnick", "2006-01-03 15:04:05Z"))
since, complete := betweenTimestamps(buf, pastTime, time.Now(), 0)
if len(since) != 0 {
@@ -40,9 +38,7 @@ func TestEmptyBuffer(t *testing.T) {
since, complete = betweenTimestamps(buf, pastTime, time.Now(), 0)
assertEqual(complete, true, t)
assertEqual(len(since), 0, t)
buf.Add(Item{
Nick: "testnick",
})
buf.Add(easyItem("testnick", "2006-01-03 15:04:05Z"))
since, complete = betweenTimestamps(buf, pastTime, time.Now(), 0)
if len(since) != 1 {
t.Error("should be able to store items in a nonempty buffer")
@@ -54,9 +50,7 @@ func TestEmptyBuffer(t *testing.T) {
t.Error("retrived junk data")
}
buf.Add(Item{
Nick: "testnick2",
})
buf.Add(easyItem("testnick2", "2006-01-04 15:04:05Z"))
since, complete = betweenTimestamps(buf, pastTime, time.Now(), 0)
if len(since) != 1 {
t.Error("expect exactly 1 item")