| Index: common/lazyslot/lazyslot_test.go
|
| diff --git a/common/lazyslot/lazyslot_test.go b/common/lazyslot/lazyslot_test.go
|
| index c221590cde340eb9d37c92d1e03ad741a5ec16f1..c8b50a2d5596a6cd93d6c13d15701b05766ad85b 100644
|
| --- a/common/lazyslot/lazyslot_test.go
|
| +++ b/common/lazyslot/lazyslot_test.go
|
| @@ -9,30 +9,35 @@ import (
|
| "testing"
|
| "time"
|
|
|
| + "golang.org/x/net/context"
|
| +
|
| "github.com/luci/luci-go/common/clock/testclock"
|
|
|
| + . "github.com/luci/luci-go/common/testing/assertions"
|
| . "github.com/smartystreets/goconvey/convey"
|
| - "golang.org/x/net/context"
|
| )
|
|
|
| func TestLazySlot(t *testing.T) {
|
| Convey("Blocking mode works", t, func() {
|
| c, clk := newContext()
|
|
|
| + lock := sync.Mutex{}
|
| counter := 0
|
| +
|
| s := Slot{
|
| Fetcher: func(c context.Context, prev Value) (Value, error) {
|
| + lock.Lock()
|
| + defer lock.Unlock()
|
| counter++
|
| return Value{counter, clk.Now().Add(time.Second)}, nil
|
| },
|
| }
|
|
|
| // Initial fetch.
|
| - So(s.Peek(), ShouldResemble, Value{})
|
| + So(s.current, ShouldBeNil)
|
| v, err := s.Get(c)
|
| So(err, ShouldBeNil)
|
| So(v.Value.(int), ShouldEqual, 1)
|
| - So(s.Peek().Value.(int), ShouldEqual, 1)
|
|
|
| // Still fresh.
|
| v, err = s.Get(c)
|
| @@ -113,7 +118,8 @@ func TestLazySlot(t *testing.T) {
|
| s.Fetcher = func(c context.Context, prev Value) (Value, error) {
|
| panic("omg")
|
| }
|
| - So(func() { s.Get(c) }, ShouldPanicWith, "omg")
|
| + _, err = s.Get(c)
|
| + So(err, ShouldErrLike, "panic caught in lazyslot.Slot Fetcher - omg")
|
|
|
| // Doesn't deadlock.
|
| s.Fetcher = func(c context.Context, prev Value) (Value, error) {
|
| @@ -123,6 +129,17 @@ func TestLazySlot(t *testing.T) {
|
| So(err, ShouldBeNil)
|
| So(v.Value.(int), ShouldEqual, 2)
|
| })
|
| +
|
| + Convey("Checks for nil", t, func(conv C) {
|
| + c, clk := newContext()
|
| + s := Slot{
|
| + Fetcher: func(c context.Context, prev Value) (Value, error) {
|
| + return Value{nil, clk.Now().Add(time.Second)}, nil
|
| + },
|
| + }
|
| + _, err := s.Get(c)
|
| + So(err, ShouldErrLike, "lazyslot.Slot Fetcher returned nil value")
|
| + })
|
| }
|
|
|
| func newContext() (context.Context, testclock.TestClock) {
|
|
|