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

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: Actually upload the patch. 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
« no previous file with comments | « common/clock/systemclock.go ('k') | common/clock/systemtimer.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // timeBase is the amount of time where short-response goroutine events "should
17 // happen". This isn't a great measure, since scheduling can take longer. Making
18 // this short will make the test run faster at the possible expense of increased
19 // raciness. Making this longer will increase test time, but will potentially
20 // reduce the change of race-related errors.
21 //
22 // This should be kept >60ms which is a fairly gratuitous RTC-based scheduler
23 // delay (1 hr / 2^16) that some older OSes may be subject to.
24 const timeBase = 60 * time.Millisecond
25
26 // veryLongTime is a time long enough that it won't feasably happen during the
27 // course of test execution.
28 const veryLongTime = 1000 * timeBase
29
30 // TestSystemClock tests the non-trivial system clock methods.
31 func TestSystemClock(t *testing.T) {
32 t.Parallel()
33
34 Convey(`A cancelable Context`, t, func() {
35 c, cancelFunc := context.WithCancel(context.Background())
36 sc := GetSystemClock()
37
38 Convey(`Will perform a full sleep if the Context isn't canceled. `, func() {
39 So(sc.Sleep(c, timeBase), ShouldBeNil)
40 })
41
42 Convey(`Will terminate the Sleep prematurely if the Context is c anceled.`, func() {
43 cancelFunc()
44 So(sc.Sleep(c, veryLongTime), ShouldEqual, context.Cance led)
45 })
46 })
47 }
OLDNEW
« no previous file with comments | « common/clock/systemclock.go ('k') | common/clock/systemtimer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698