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