Index: go/src/infra/libs/clock/systemtimer_test.go |
diff --git a/go/src/infra/libs/clock/systemtimer_test.go b/go/src/infra/libs/clock/systemtimer_test.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aac070782f1084259aaee5efc447d1251a3a6e48 |
--- /dev/null |
+++ b/go/src/infra/libs/clock/systemtimer_test.go |
@@ -0,0 +1,63 @@ |
+// Copyright 2015 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" |
+ |
+ . "github.com/smartystreets/goconvey/convey" |
+) |
+ |
+func TestSystemTimer(t *testing.T) { |
iannucci
2015/06/03 17:37:20
in general we should be in the habit of starting a
dnj
2015/06/03 18:21:27
Done.
|
+ Convey(`A systemTimer instance`, t, func() { |
+ t := new(systemTimer) |
+ |
+ Convey(`Should start with a nil channel.`, func() { |
+ So(t.GetC(), ShouldBeNil) |
+ }) |
+ |
+ Convey(`When stopped, should return inactive.`, func() { |
+ So(t.Stop(), ShouldBeFalse) |
+ }) |
+ |
+ Convey(`When reset`, func() { |
+ active := t.Reset(1 * time.Hour) |
+ So(active, ShouldBeFalse) |
+ |
+ Convey(`When reset to a short duration`, func() { |
+ active := t.Reset(1 * time.Microsecond) |
+ |
+ Convey(`Should return active.`, func() { |
+ So(active, ShouldBeTrue) |
+ }) |
+ |
+ Convey(`Should trigger shortly.`, func() { |
+ tm := <-t.GetC() |
+ So(tm, ShouldNotResemble, time.Time{}) |
+ }) |
+ }) |
+ |
+ Convey(`When stopped, should return active and have a non-nil C.`, func() { |
+ active := t.Stop() |
+ So(active, ShouldBeTrue) |
+ So(t.GetC(), ShouldNotBeNil) |
+ }) |
+ |
+ Convey(`When stopped, should return active.`, func() { |
+ active := t.Stop() |
+ So(active, ShouldBeTrue) |
+ }) |
+ |
+ Convey(`Should have a non-nil channel.`, func() { |
+ So(t.GetC(), ShouldNotBeNil) |
+ }) |
+ |
+ Reset(func() { |
+ t.Stop() |
+ }) |
+ }) |
+ }) |
+} |