OLD | NEW |
(Empty) | |
| 1 // Copyright 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 clock |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 "time" |
| 10 |
| 11 . "github.com/smartystreets/goconvey/convey" |
| 12 ) |
| 13 |
| 14 func TestSystemTimer(t *testing.T) { |
| 15 t.Parallel() |
| 16 |
| 17 Convey(`A systemTimer instance`, t, func() { |
| 18 t := new(systemTimer) |
| 19 |
| 20 Convey(`Should start with a nil channel.`, func() { |
| 21 So(t.GetC(), ShouldBeNil) |
| 22 }) |
| 23 |
| 24 Convey(`When stopped, should return inactive.`, func() { |
| 25 So(t.Stop(), ShouldBeFalse) |
| 26 }) |
| 27 |
| 28 Convey(`When reset`, func() { |
| 29 active := t.Reset(1 * time.Hour) |
| 30 So(active, ShouldBeFalse) |
| 31 |
| 32 Convey(`When reset to a short duration`, func() { |
| 33 active := t.Reset(1 * time.Microsecond) |
| 34 |
| 35 Convey(`Should return active.`, func() { |
| 36 So(active, ShouldBeTrue) |
| 37 }) |
| 38 |
| 39 Convey(`Should trigger shortly.`, func() { |
| 40 tm := <-t.GetC() |
| 41 So(tm, ShouldNotResemble, time.Time{}) |
| 42 }) |
| 43 }) |
| 44 |
| 45 Convey(`When stopped, should return active and have a no
n-nil C.`, func() { |
| 46 active := t.Stop() |
| 47 So(active, ShouldBeTrue) |
| 48 So(t.GetC(), ShouldNotBeNil) |
| 49 }) |
| 50 |
| 51 Convey(`When stopped, should return active.`, func() { |
| 52 active := t.Stop() |
| 53 So(active, ShouldBeTrue) |
| 54 }) |
| 55 |
| 56 Convey(`Should have a non-nil channel.`, func() { |
| 57 So(t.GetC(), ShouldNotBeNil) |
| 58 }) |
| 59 |
| 60 Reset(func() { |
| 61 t.Stop() |
| 62 }) |
| 63 }) |
| 64 }) |
| 65 } |
OLD | NEW |