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

Side by Side Diff: client/internal/logdog/butler/bundler/timeoutCond_test.go

Issue 1412063008: logdog: Add bundler library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Updated from comments. Created 5 years, 1 month 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 | « client/internal/logdog/butler/bundler/timeoutCond.go ('k') | no next file » | 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 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 bundler
6
7 import (
8 "sync"
9 "testing"
10 "time"
11
12 "github.com/luci/luci-go/common/clock"
13 "github.com/luci/luci-go/common/clock/testclock"
14 . "github.com/smartystreets/goconvey/convey"
15 )
16
17 func TestTimeoutCond(t *testing.T) {
18 Convey(`A timeout Cond bound to a lock`, t, func() {
19 l := sync.Mutex{}
20 tc := testclock.New(time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC))
21 c := newTimeoutCond(tc, &l)
22
23 Convey(`Will wait without a timer if the duration is <0`, func() {
24 didSetTimer := false
25 tc.SetTimerCallback(func(time.Duration, clock.Timer) {
26 didSetTimer = true
27 })
28
29 l.Lock()
30 defer l.Unlock()
31
32 // Signal the Cond until we unblock.
33 go func() {
34 l.Lock()
35 defer l.Unlock()
36
37 c.Signal()
38 }()
39
40 timeout := c.waitTimeout(-1)
41 So(didSetTimer, ShouldBeFalse)
42 So(timeout, ShouldBeFalse)
43 })
44
45 Convey(`Will timeout after the duration expires.`, func() {
46 tc.SetTimerCallback(func(time.Duration, clock.Timer) {
47 tc.Add(time.Second)
48 })
49
50 l.Lock()
51 defer l.Unlock()
52
53 timeout := c.waitTimeout(time.Second)
54 So(timeout, ShouldBeTrue)
55 })
56
57 Convey(`Will not timeout if signalled before the timeout.`, func () {
58 tc.SetTimerCallback(func(time.Duration, clock.Timer) {
59 tc.Add(time.Second)
60 })
61
62 l.Lock()
63 defer l.Unlock()
64
65 t := tc.NewTimer()
66 t.Reset(time.Second)
67 go func() {
68 <-t.GetC()
69 c.Signal()
70 }()
71
72 timeout := c.waitTimeout(5 * time.Second)
73 So(timeout, ShouldBeFalse)
74 })
75 })
76 }
OLDNEW
« no previous file with comments | « client/internal/logdog/butler/bundler/timeoutCond.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698