OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "golang.org/x/net/context" |
| 12 |
| 13 . "github.com/smartystreets/goconvey/convey" |
| 14 ) |
| 15 |
| 16 // TestSystemClock tests the non-trivial system clock methods. |
| 17 func TestSystemClock(t *testing.T) { |
| 18 t.Parallel() |
| 19 |
| 20 Convey(`A cancelable Context`, t, func() { |
| 21 c, cancelFunc := context.WithCancel(context.Background()) |
| 22 sc := GetSystemClock() |
| 23 |
| 24 Convey(`Will perform a full sleep if the Context isn't canceled.
`, func() { |
| 25 So(sc.Sleep(c, 100*time.Millisecond), ShouldBeNil) |
| 26 }) |
| 27 |
| 28 Convey(`Will return Context error if canceled.`, func() { |
| 29 cancelFunc() |
| 30 So(sc.Sleep(c, 1*time.Hour), ShouldEqual, context.Cancel
ed) |
| 31 }) |
| 32 |
| 33 Convey(`Will terminate the Sleep prematurely if the Context is c
anceled.`, func() { |
| 34 cancelFunc() |
| 35 So(sc.Sleep(c, 1*time.Hour), ShouldEqual, context.Cancel
ed) |
| 36 }) |
| 37 }) |
| 38 } |
OLD | NEW |