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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/internal/logdog/butler/bundler/timeoutCond.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/internal/logdog/butler/bundler/timeoutCond_test.go
diff --git a/client/internal/logdog/butler/bundler/timeoutCond_test.go b/client/internal/logdog/butler/bundler/timeoutCond_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..f855d12ce5ccbe6d428e9ecf41c602d9787f33a2
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/timeoutCond_test.go
@@ -0,0 +1,76 @@
+// 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 bundler
+
+import (
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/luci/luci-go/common/clock"
+ "github.com/luci/luci-go/common/clock/testclock"
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestTimeoutCond(t *testing.T) {
+ Convey(`A timeout Cond bound to a lock`, t, func() {
+ l := sync.Mutex{}
+ tc := testclock.New(time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC))
+ c := newTimeoutCond(tc, &l)
+
+ Convey(`Will wait without a timer if the duration is <0`, func() {
+ didSetTimer := false
+ tc.SetTimerCallback(func(time.Duration, clock.Timer) {
+ didSetTimer = true
+ })
+
+ l.Lock()
+ defer l.Unlock()
+
+ // Signal the Cond until we unblock.
+ go func() {
+ l.Lock()
+ defer l.Unlock()
+
+ c.Signal()
+ }()
+
+ timeout := c.waitTimeout(-1)
+ So(didSetTimer, ShouldBeFalse)
+ So(timeout, ShouldBeFalse)
+ })
+
+ Convey(`Will timeout after the duration expires.`, func() {
+ tc.SetTimerCallback(func(time.Duration, clock.Timer) {
+ tc.Add(time.Second)
+ })
+
+ l.Lock()
+ defer l.Unlock()
+
+ timeout := c.waitTimeout(time.Second)
+ So(timeout, ShouldBeTrue)
+ })
+
+ Convey(`Will not timeout if signalled before the timeout.`, func() {
+ tc.SetTimerCallback(func(time.Duration, clock.Timer) {
+ tc.Add(time.Second)
+ })
+
+ l.Lock()
+ defer l.Unlock()
+
+ t := tc.NewTimer()
+ t.Reset(time.Second)
+ go func() {
+ <-t.GetC()
+ c.Signal()
+ }()
+
+ timeout := c.waitTimeout(5 * time.Second)
+ So(timeout, ShouldBeFalse)
+ })
+ })
+}
« 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