From d47d7a8bdfd8db5b1232eca628171154180c4f1e Mon Sep 17 00:00:00 2001 From: Matt Ouille Date: Tue, 7 Jul 2026 16:57:20 -0700 Subject: [PATCH] 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. --- irc/history/history_test.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/irc/history/history_test.go b/irc/history/history_test.go index 18ee965c..29c2d523 100644 --- a/irc/history/history_test.go +++ b/irc/history/history_test.go @@ -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")