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

Unified Diff: common/clock/systemclock_test.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: More test coverage, cleanup, consolidation. 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/systemclock_test.go
diff --git a/common/clock/systemclock_test.go b/common/clock/systemclock_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..d409222339f4d47fbf23f1900d79515846d9f53b
--- /dev/null
+++ b/common/clock/systemclock_test.go
@@ -0,0 +1,38 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package clock
+
+import (
+ "testing"
+ "time"
+
+ "golang.org/x/net/context"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+// TestSystemClock tests the non-trivial system clock methods.
+func TestSystemClock(t *testing.T) {
+ t.Parallel()
+
+ Convey(`A cancelable Context`, t, func() {
+ c, cancelFunc := context.WithCancel(context.Background())
+ sc := GetSystemClock()
+
+ Convey(`Will perform a full sleep if the Context isn't canceled.`, func() {
+ So(sc.Sleep(c, 100*time.Millisecond), ShouldBeNil)
+ })
+
+ Convey(`Will return Context error if canceled.`, func() {
+ cancelFunc()
+ So(sc.Sleep(c, 1*time.Hour), ShouldEqual, context.Canceled)
+ })
+
+ Convey(`Will terminate the Sleep prematurely if the Context is canceled.`, func() {
+ cancelFunc()
+ So(sc.Sleep(c, 1*time.Hour), ShouldEqual, context.Canceled)
+ })
+ })
+}

Powered by Google App Engine
This is Rietveld 408576698