Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: common/clock/systemtimer_test.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Much more invasive, cancel by default, remove meter package. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: common/clock/systemtimer_test.go
diff --git a/common/clock/systemtimer_test.go b/common/clock/systemtimer_test.go
index 8b9cbc54174ea2dfe1f4d9fb861fe771ad73ecb0..39d0a731b054a1d967864118fa303dcbd13e63a6 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,16 +17,24 @@ 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 prematurely if canceled.`, 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)
@@ -58,10 +68,6 @@ func TestSystemTimer(t *testing.T) {
Convey(`Should have a non-nil channel.`, func() {
So(t.GetC(), ShouldNotBeNil)
})
-
- Reset(func() {
- t.Stop()
- })
})
})
}

Powered by Google App Engine
This is Rietveld 408576698