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

Side by Side Diff: common/clock/systemclock_test.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: More test coverage, cleanup, consolidation. Created 4 years, 10 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 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698