Chromium Code Reviews| Index: go/src/infra/libs/clock/testclock/testclock_test.go |
| diff --git a/go/src/infra/libs/clock/testclock/testclock_test.go b/go/src/infra/libs/clock/testclock/testclock_test.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a50383c339c14c85d329f3ba4ddc4ee501c3b944 |
| --- /dev/null |
| +++ b/go/src/infra/libs/clock/testclock/testclock_test.go |
| @@ -0,0 +1,59 @@ |
| +// Copyright 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" |
| + "infra/libs/clock" |
| +) |
| + |
| +func TestTestClock(t *testing.T) { |
| + Convey(`A testing clock instance`, t, func() { |
| + now := time.Date(2015, 01, 01, 00, 00, 00, 00, time.UTC) |
| + c := New(now) |
| + |
| + Convey(`Returns the current time.`, func() { |
| + So(c.Now(), ShouldResemble, now) |
| + }) |
| + |
| + Convey(`When sleeping with a time of zero, immediately awakens.`, func() { |
| + c.Sleep(0) |
| + So(c.Now(), ShouldResemble, now) |
| + }) |
| + |
| + Convey(`When sleeping for a period of time, awakens when signalled.`, func() { |
| + sleepingC := make(chan struct{}) |
| + c.SetTimerCallback(func(_ clock.Timer) { |
| + close(sleepingC) |
| + }) |
| + |
| + awakeC := make(chan time.Time) |
| + go func() { |
| + c.Sleep(2 * time.Second) |
| + awakeC <- c.Now() |
| + }() |
| + |
| + <-sleepingC |
| + c.Set(now.Add(1 * time.Second)) |
| + c.Set(now.Add(2 * time.Second)) |
| + So(<-awakeC, ShouldResemble, now.Add(2*time.Second)) |
| + }) |
| + |
| + Convey(`Awakens after a period of time.`, func() { |
| + afterC := c.After(2 * time.Second) |
| + awakeC := make(chan time.Time) |
| + go func() { |
| + awakeC <- <-afterC |
|
iannucci
2015/06/03 17:37:20
well that's a very odd construction... why not jus
dnj
2015/06/03 18:21:27
Heh no idea.
|
| + }() |
| + |
| + c.Set(now.Add(1 * time.Second)) |
| + c.Set(now.Add(2 * time.Second)) |
| + So(<-awakeC, ShouldResemble, now.Add(2*time.Second)) |
| + }) |
| + }) |
| +} |