| Index: common/clock/systemtimer_test.go
|
| diff --git a/common/clock/systemtimer_test.go b/common/clock/systemtimer_test.go
|
| index 8b9cbc54174ea2dfe1f4d9fb861fe771ad73ecb0..1ef2cd059165a19716a892ef58b24be59bbafaef 100644
|
| --- a/common/clock/systemtimer_test.go
|
| +++ b/common/clock/systemtimer_test.go
|
| @@ -8,6 +8,8 @@ import (
|
| "testing"
|
| "time"
|
|
|
| + "golang.org/x/net/context"
|
| +
|
| . "github.com/smartystreets/goconvey/convey"
|
| )
|
|
|
| @@ -15,33 +17,44 @@ func TestSystemTimer(t *testing.T) {
|
| t.Parallel()
|
|
|
| Convey(`A systemTimer instance`, t, func() {
|
| - t := new(systemTimer)
|
| + ctx, cancelFunc := context.WithCancel(context.Background())
|
| + t := GetSystemClock().NewTimer(ctx)
|
| + defer t.Stop()
|
|
|
| - Convey(`Should start with a nil channel.`, func() {
|
| - So(t.GetC(), ShouldBeNil)
|
| + Convey(`Should start with a non-nil channel.`, func() {
|
| + So(t.GetC(), ShouldNotBeNil)
|
| })
|
|
|
| Convey(`When stopped, should return inactive.`, func() {
|
| So(t.Stop(), ShouldBeFalse)
|
| })
|
|
|
| + Convey(`Will return immediately if the Context is canceled before Reset.`, func() {
|
| + cancelFunc()
|
| +
|
| + t.Reset(time.Hour)
|
| + So((<-t.GetC()).Err, ShouldEqual, context.Canceled)
|
| + })
|
| +
|
| + Convey(`Will return if the Context is canceled after Reset.`, func() {
|
| + t.Reset(time.Hour)
|
| + cancelFunc()
|
| +
|
| + So((<-t.GetC()).Err, ShouldEqual, context.Canceled)
|
| + })
|
| +
|
| Convey(`When reset`, func() {
|
| - active := t.Reset(1 * time.Hour)
|
| - So(active, ShouldBeFalse)
|
| + So(t.Reset(1*time.Hour), ShouldBeFalse)
|
|
|
| - Convey(`When reset to a short duration`, func() {
|
| + Convey(`When reset again to a short duration, should return that it was active and trigger.`, func() {
|
| // Upper bound of supported platform resolution. Windows is 15ms, so
|
| // make sure we exceed that.
|
| - active := t.Reset(100 * time.Millisecond)
|
| -
|
| - Convey(`Should return active.`, func() {
|
| - So(active, ShouldBeTrue)
|
| - })
|
| + So(t.Reset(100*time.Millisecond), ShouldBeTrue)
|
| + So((<-t.GetC()).IsZero(), ShouldBeFalse)
|
|
|
| - Convey(`Should trigger shortly.`, func() {
|
| - tm := <-t.GetC()
|
| - So(tm, ShouldNotResemble, time.Time{})
|
| - })
|
| + // Again (reschedule).
|
| + So(t.Reset(100*time.Millisecond), ShouldBeFalse)
|
| + So((<-t.GetC()).IsZero(), ShouldBeFalse)
|
| })
|
|
|
| Convey(`When stopped, should return active and have a non-nil C.`, func() {
|
| @@ -58,10 +71,6 @@ func TestSystemTimer(t *testing.T) {
|
| Convey(`Should have a non-nil channel.`, func() {
|
| So(t.GetC(), ShouldNotBeNil)
|
| })
|
| -
|
| - Reset(func() {
|
| - t.Stop()
|
| - })
|
| })
|
| })
|
| }
|
|
|