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

Side by Side 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, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package lazyslot 5 package lazyslot
6 6
7 import ( 7 import (
8 "fmt"
8 "sync" 9 "sync"
9 "testing" 10 "testing"
10 "time" 11 "time"
11 12
12 "golang.org/x/net/context" 13 "golang.org/x/net/context"
13 14
15 "github.com/luci/luci-go/common/clock"
14 "github.com/luci/luci-go/common/clock/testclock" 16 "github.com/luci/luci-go/common/clock/testclock"
17 "github.com/luci/luci-go/common/retry"
15 18
16 . "github.com/luci/luci-go/common/testing/assertions" 19 . "github.com/luci/luci-go/common/testing/assertions"
17 . "github.com/smartystreets/goconvey/convey" 20 . "github.com/smartystreets/goconvey/convey"
18 ) 21 )
19 22
20 func TestLazySlot(t *testing.T) { 23 func TestLazySlot(t *testing.T) {
21 Convey("Blocking mode works", t, func() { 24 Convey("Blocking mode works", t, func() {
22 c, clk := newContext() 25 c, clk := newContext()
23 26
24 lock := sync.Mutex{} 27 lock := sync.Mutex{}
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 Convey("Checks for nil", t, func(conv C) { 136 Convey("Checks for nil", t, func(conv C) {
134 c, clk := newContext() 137 c, clk := newContext()
135 s := Slot{ 138 s := Slot{
136 Fetcher: func(c context.Context, prev Value) (Value, err or) { 139 Fetcher: func(c context.Context, prev Value) (Value, err or) {
137 return Value{nil, clk.Now().Add(time.Second)}, n il 140 return Value{nil, clk.Now().Add(time.Second)}, n il
138 }, 141 },
139 } 142 }
140 _, err := s.Get(c) 143 _, err := s.Get(c)
141 So(err, ShouldErrLike, "lazyslot.Slot Fetcher returned nil value ") 144 So(err, ShouldErrLike, "lazyslot.Slot Fetcher returned nil value ")
142 }) 145 })
146
147 Convey("Does retries", t, func(conv C) {
148 c, clk := newContext()
149
150 clk.SetTimerCallback(func(d time.Duration, t clock.Timer) {
151 if testclock.HasTags(t, "retry") {
152 clk.Add(d)
153 }
154 })
155
156 lock := sync.Mutex{}
157 calls := 0
158
159 s := Slot{
160 RetryFactory: retry.Default,
161 Fetcher: func(c context.Context, prev Value) (Value, err or) {
162 lock.Lock()
163 calls++
164 lock.Unlock()
165 return Value{}, fmt.Errorf("omg, error")
166 },
167 }
168 _, err := s.Get(c)
169 So(err, ShouldErrLike, "context deadline exceeded")
170 So(calls, ShouldEqual, 8) // depends on retry config and deadlin e
171 })
143 } 172 }
144 173
145 func newContext() (context.Context, testclock.TestClock) { 174 func newContext() (context.Context, testclock.TestClock) {
146 return testclock.UseTime(context.Background(), time.Unix(1442270520, 0)) 175 return testclock.UseTime(context.Background(), time.Unix(1442270520, 0))
147 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698