Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: go/src/infra/libs/clock/testclock/testclock_test.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Added coverage files. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 testclock
6
7 import (
8 "testing"
9 "time"
10
11 . "github.com/smartystreets/goconvey/convey"
12 "infra/libs/clock"
13 )
14
15 func TestTestClock(t *testing.T) {
16 t.Parallel()
17
18 Convey(`A testing clock instance`, t, func() {
19 now := time.Date(2015, 01, 01, 00, 00, 00, 00, time.UTC)
20 c := New(now)
21
22 Convey(`Returns the current time.`, func() {
23 So(c.Now(), ShouldResemble, now)
24 })
25
26 Convey(`When sleeping with a time of zero, immediately awakens.` , func() {
27 c.Sleep(0)
28 So(c.Now(), ShouldResemble, now)
29 })
30
31 Convey(`When sleeping for a period of time, awakens when signall ed.`, func() {
32 sleepingC := make(chan struct{})
33 c.SetTimerCallback(func(_ clock.Timer) {
34 close(sleepingC)
35 })
36
37 awakeC := make(chan time.Time)
38 go func() {
39 c.Sleep(2 * time.Second)
40 awakeC <- c.Now()
41 }()
42
43 <-sleepingC
44 c.Set(now.Add(1 * time.Second))
45 c.Set(now.Add(2 * time.Second))
46 So(<-awakeC, ShouldResemble, now.Add(2*time.Second))
47 })
48
49 Convey(`Awakens after a period of time.`, func() {
50 afterC := c.After(2 * time.Second)
51
52 c.Set(now.Add(1 * time.Second))
53 c.Set(now.Add(2 * time.Second))
54 So(<-afterC, ShouldResemble, now.Add(2*time.Second))
55 })
56 })
57 }
OLDNEW
« no previous file with comments | « go/src/infra/libs/clock/testclock/testclock.infra_testing ('k') | go/src/infra/libs/clock/testclock/testtimer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698