OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package testclock |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 "time" |
| 10 |
| 11 . "github.com/smartystreets/goconvey/convey" |
| 12 ) |
| 13 |
| 14 func TestTestTimer(t *testing.T) { |
| 15 Convey(`A timer instance`, t, func() { |
| 16 t := NewTimer() |
| 17 |
| 18 Convey(`Should have a non-nil C.`, func() { |
| 19 So(t.GetC(), ShouldNotBeNil) |
| 20 }) |
| 21 |
| 22 Convey(`When set to Active`, func() { |
| 23 t.(*timer).active = true |
| 24 |
| 25 Convey(`When reset, should return active.`, func() { |
| 26 active := t.Reset(1 * time.Hour) |
| 27 So(active, ShouldBeTrue) |
| 28 }) |
| 29 |
| 30 Convey(`When stopped, should return active.`, func() { |
| 31 So(t.Stop(), ShouldBeTrue) |
| 32 |
| 33 Convey(`And when stopped again, should return in
active.`, func() { |
| 34 So(t.Stop(), ShouldBeFalse) |
| 35 }) |
| 36 }) |
| 37 }) |
| 38 |
| 39 Convey(`Should successfully signal.`, func() { |
| 40 t.Signal(time.Time{}) |
| 41 |
| 42 var signalled bool |
| 43 select { |
| 44 case <-t.GetC(): |
| 45 signalled = true |
| 46 default: |
| 47 break |
| 48 } |
| 49 So(signalled, ShouldBeTrue) |
| 50 }) |
| 51 }) |
| 52 } |
OLD | NEW |