From 25459af56f6e8d6939587abd48a76587928685d5 Mon Sep 17 00:00:00 2001 From: Harry Pidcock Date: Wed, 3 Jul 2024 14:19:55 +1000 Subject: [PATCH] fix: testclock.Clock alarm at now without advance --- testclock/clock.go | 2 +- testclock/clock_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/testclock/clock.go b/testclock/clock.go index f6c5c9c..79395c2 100644 --- a/testclock/clock.go +++ b/testclock/clock.go @@ -277,7 +277,7 @@ func (clock *Clock) resetTime(t *timer, deadline time.Time) bool { } t.deadline = deadline sort.Sort(byDeadline(clock.waiting)) - if clock.now.After(t.deadline) { + if !clock.now.Before(t.deadline) { // If the time has already passed, that means we should be triggering the // Timer right away, as "now" has already occurred. clock.triggerAll() diff --git a/testclock/clock_test.go b/testclock/clock_test.go index 8671317..77f0277 100644 --- a/testclock/clock_test.go +++ b/testclock/clock_test.go @@ -425,3 +425,14 @@ func (*clockSuite) TestPastAlarmFired(c *gc.C) { c.Fatal("alarm did not fire by deadline") } } + +func (*clockSuite) TestNowAlarmFired(c *gc.C) { + t0 := time.Now() + cl := testclock.NewClock(t0) + alarm := cl.NewAlarm(cl.Now()) + select { + case <-alarm.Chan(): + case <-time.After(testing.ShortWait): + c.Fatal("alarm did not fire by deadline") + } +}