Skip to content

Commit

Permalink
Merge pull request #14 from hpidcock/add-alarms
Browse files Browse the repository at this point in the history
fix: testclock.Clock alarm at now without advance
  • Loading branch information
hpidcock authored Jul 3, 2024
2 parents 5802510 + 25459af commit 20b89ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion testclock/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions testclock/clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 20b89ef

Please sign in to comment.