Skip to content

Commit 123636d

Browse files
Merge pull request #24 from lyonssp/master
FakeClock.After should short-circuit for negative inputs
2 parents 56678c9 + 297dc93 commit 123636d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clockwork.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (fc *fakeClock) After(d time.Duration) <-chan time.Time {
9797
defer fc.l.Unlock()
9898
now := fc.time
9999
done := make(chan time.Time, 1)
100-
if d.Nanoseconds() == 0 {
100+
if d.Nanoseconds() <= 0 {
101101
// special case - trigger immediately
102102
done <- now
103103
} else {

clockwork_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
func TestFakeClockAfter(t *testing.T) {
1010
fc := &fakeClock{}
1111

12+
neg := fc.After(-1)
13+
select {
14+
case <-neg:
15+
default:
16+
t.Errorf("negative did not return!")
17+
}
18+
1219
zero := fc.After(0)
1320
select {
1421
case <-zero:

0 commit comments

Comments
 (0)