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) |
+ }) |
+ }) |
+} |