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

Unified Diff: go/src/infra/libs/clock/testclock/testtimer_test.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Refactored into sub-packages. Created 5 years, 7 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: go/src/infra/libs/clock/testclock/testtimer_test.go
diff --git a/go/src/infra/libs/clock/testclock/testtimer_test.go b/go/src/infra/libs/clock/testclock/testtimer_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..685eeb582529b2d5eb669edb2b2529d98308dca5
--- /dev/null
+++ b/go/src/infra/libs/clock/testclock/testtimer_test.go
@@ -0,0 +1,52 @@
+// Copyright (c) 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 testclock
+
+import (
+ "testing"
+ "time"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestTestTimer(t *testing.T) {
+ Convey(`A timer instance`, t, func() {
+ t := NewTimer()
+
+ Convey(`Should have a non-nil C.`, func() {
+ So(t.GetC(), ShouldNotBeNil)
+ })
+
+ Convey(`When set to Active`, func() {
+ t.(*timer).active = true
+
+ Convey(`When reset, should return active.`, func() {
+ active := t.Reset(1 * time.Hour)
+ So(active, ShouldBeTrue)
+ })
+
+ Convey(`When stopped, should return active.`, func() {
+ So(t.Stop(), ShouldBeTrue)
+
+ Convey(`And when stopped again, should return inactive.`, func() {
+ So(t.Stop(), ShouldBeFalse)
+ })
+ })
+ })
+
+ Convey(`Should successfully signal.`, func() {
+ t.Signal(time.Time{})
+
+ var signalled bool
+ select {
+ case <-t.GetC():
+ signalled = true
+ default:
+ break
+ }
+ So(signalled, ShouldBeTrue)
+ })
+ })
+}

Powered by Google App Engine
This is Rietveld 408576698