From 072b84870c20e1b973869e7b97034d39e45e5c2a Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 16 Dec 2018 20:59:32 +0630 Subject: [PATCH] don't fire a newly created timer --- internal/utils/timer.go | 7 +++++-- internal/utils/timer_test.go | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/utils/timer.go b/internal/utils/timer.go index 20eaacd0..15e6fb05 100644 --- a/internal/utils/timer.go +++ b/internal/utils/timer.go @@ -1,6 +1,9 @@ package utils -import "time" +import ( + "math" + "time" +) // A Timer wrapper that behaves correctly when resetting type Timer struct { @@ -11,7 +14,7 @@ type Timer struct { // NewTimer creates a new timer that is not set func NewTimer() *Timer { - return &Timer{t: time.NewTimer(0)} + return &Timer{t: time.NewTimer(time.Duration(math.MaxInt64))} } // Chan returns the channel of the wrapped timer diff --git a/internal/utils/timer_test.go b/internal/utils/timer_test.go index c1581919..cf26785b 100644 --- a/internal/utils/timer_test.go +++ b/internal/utils/timer_test.go @@ -10,6 +10,11 @@ import ( var _ = Describe("Timer", func() { const d = 10 * time.Millisecond + It("doesn't fire a newly created timer", func() { + t := NewTimer() + Consistently(t.Chan()).ShouldNot(Receive()) + }) + It("works", func() { t := NewTimer() t.Reset(time.Now().Add(d))