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

Unified Diff: common/lazyslot/lazyslot_test.go

Issue 1748933002: Retry RPC deadlines when fetching GAE settings. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@simplify-lazyslot
Patch Set: use clock tags to properly advance time in test 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 side-by-side diff with in-line comments
Download patch
Index: common/lazyslot/lazyslot_test.go
diff --git a/common/lazyslot/lazyslot_test.go b/common/lazyslot/lazyslot_test.go
index c8b50a2d5596a6cd93d6c13d15701b05766ad85b..f0f9a1b63dd22a0193d8ca83a9604d6c38c0bf89 100644
--- a/common/lazyslot/lazyslot_test.go
+++ b/common/lazyslot/lazyslot_test.go
@@ -5,13 +5,16 @@
package lazyslot
import (
+ "fmt"
"sync"
"testing"
"time"
"golang.org/x/net/context"
+ "github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/clock/testclock"
+ "github.com/luci/luci-go/common/retry"
. "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
@@ -140,6 +143,32 @@ func TestLazySlot(t *testing.T) {
_, err := s.Get(c)
So(err, ShouldErrLike, "lazyslot.Slot Fetcher returned nil value")
})
+
+ Convey("Does retries", t, func(conv C) {
+ c, clk := newContext()
+
+ clk.SetTimerCallback(func(d time.Duration, t clock.Timer) {
+ if testclock.HasTags(t, "retry") {
+ clk.Add(d)
+ }
+ })
+
+ lock := sync.Mutex{}
+ calls := 0
+
+ s := Slot{
+ RetryFactory: retry.Default,
+ Fetcher: func(c context.Context, prev Value) (Value, error) {
+ lock.Lock()
+ calls++
+ lock.Unlock()
+ return Value{}, fmt.Errorf("omg, error")
+ },
+ }
+ _, err := s.Get(c)
+ So(err, ShouldErrLike, "context deadline exceeded")
+ So(calls, ShouldEqual, 8) // depends on retry config and deadline
+ })
}
func newContext() (context.Context, testclock.TestClock) {

Powered by Google App Engine
This is Rietveld 408576698