Index: go/src/infra/gae/libs/wrapper/memory/memcache_test.go |
diff --git a/go/src/infra/gae/libs/wrapper/memory/memcache_test.go b/go/src/infra/gae/libs/wrapper/memory/memcache_test.go |
index 9225f51c7751180eeeb1c845cabab03fdcb19230..a7715af40c04f875a304cdac71e0a399a1bfdf79 100644 |
--- a/go/src/infra/gae/libs/wrapper/memory/memcache_test.go |
+++ b/go/src/infra/gae/libs/wrapper/memory/memcache_test.go |
@@ -7,6 +7,8 @@ package memory |
import ( |
"infra/gae/libs/wrapper" |
"infra/gae/libs/wrapper/unsafe" |
+ "infra/libs/clock" |
+ "infra/libs/clock/testclock" |
"testing" |
"time" |
@@ -20,13 +22,9 @@ func TestMemcache(t *testing.T) { |
t.Parallel() |
Convey("memcache", t, func() { |
- now := time.Now() |
- timeNow := func(context.Context) time.Time { |
- ret := now |
- now = now.Add(time.Second) |
- return ret |
- } |
- c := Use(wrapper.SetTimeNowFactory(context.Background(), timeNow)) |
+ now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) |
+ tc := testclock.New(now) |
+ c := Use(clock.SetClock(context.Background(), tc)) |
mc := wrapper.GetMC(c) |
mci := wrapper.GetMC(c).(*memcacheImpl) |
So(mc, ShouldNotEqual, mci) // two impls with the same memcacheData |
@@ -71,7 +69,7 @@ func TestMemcache(t *testing.T) { |
So(i, ShouldResemble, testItem) |
Convey("which can expire", func() { |
- now = now.Add(time.Second * 4) |
+ tc.Add(time.Second * 4) |
i, err := mc.Get("sup") |
So(err, ShouldEqual, memcache.ErrCacheMiss) |
So(i, ShouldBeNil) |
@@ -169,9 +167,7 @@ func TestMemcache(t *testing.T) { |
}) |
Convey("and fails if the item is expired/gone", func() { |
- // run the clock forward |
- wrapper.GetTimeNow(c) |
- wrapper.GetTimeNow(c) |
+ tc.Add(3 * time.Second) |
itm.Value = []byte("newp") |
err = mc.CompareAndSwap(itm) |
So(err, ShouldEqual, memcache.ErrNotStored) |