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

Unified Diff: go/src/infra/gae/libs/wrapper/memory/memcache_test.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Added coverage files. Created 5 years, 7 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
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/memcache.go ('k') | go/src/infra/gae/libs/wrapper/memory/taskqueue.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ab1934c7aea78b8a39f47e86d67d223e6ab8764c 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,7 @@ package memory
import (
"infra/gae/libs/wrapper"
"infra/gae/libs/wrapper/unsafe"
+ "infra/libs/clock/testclock"
"testing"
"time"
@@ -20,13 +21,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)
+ c, tc := testclock.UseTime(context.Background(), now)
+ c = Use(c)
mc := wrapper.GetMC(c)
mci := wrapper.GetMC(c).(*memcacheImpl)
So(mc, ShouldNotEqual, mci) // two impls with the same memcacheData
@@ -71,7 +68,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 +166,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)
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/memcache.go ('k') | go/src/infra/gae/libs/wrapper/memory/taskqueue.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698