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

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: Removed goroutine safety from testtimer. 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
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)

Powered by Google App Engine
This is Rietveld 408576698