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

Unified Diff: go/src/infra/gae/libs/wrapper/dummy_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/dummy_test.go
diff --git a/go/src/infra/gae/libs/wrapper/dummy_test.go b/go/src/infra/gae/libs/wrapper/dummy_test.go
index 9d4f101fb4a3de271b4477e1c2c332ed868497a3..265c20939c1dca175858c3c050ae1999d1746352 100644
--- a/go/src/infra/gae/libs/wrapper/dummy_test.go
+++ b/go/src/infra/gae/libs/wrapper/dummy_test.go
@@ -14,20 +14,23 @@ import (
"appengine/memcache"
. "github.com/smartystreets/goconvey/convey"
+ "infra/libs/clock"
+ "infra/libs/clock/testclock"
)
func TestContextAccess(t *testing.T) {
Convey("Context Access", t, func() {
c := context.Background()
+ now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
+ tc := testclock.New(now)
+ c = clock.SetClock(c, tc)
iannucci 2015/06/03 17:37:19 wdyt about c = testclock.UseTime(c, time.Date(
dnj 2015/06/03 18:21:26 You need a reference to the test clock in order to
+
Convey("blank", func() {
So(GetDS(c), ShouldBeNil)
So(GetMC(c), ShouldBeNil)
So(GetTQ(c), ShouldBeNil)
So(GetGI(c), ShouldBeNil)
-
- now := time.Now()
- So(GetTimeNow(c), ShouldHappenOnOrAfter, now)
})
Convey("DS", func() {
@@ -59,30 +62,19 @@ func TestContextAccess(t *testing.T) {
So(func() { q.Distinct() }, ShouldPanic)
})
- Convey("TimeNow", func() {
- thing := time.Date(2000, time.August, 20, 0, 0, 0, 0, time.UTC)
- c = SetTimeNow(c, &thing)
- So(GetTimeNow(c), ShouldResemble, thing)
-
- Convey("MathRand", func() {
- r := rand.New(rand.NewSource(thing.UnixNano()))
- i := r.Int()
-
- // when it's unset it picks TimeNow every time
- So(GetMathRand(c).Int(), ShouldEqual, i)
- So(GetMathRand(c).Int(), ShouldEqual, i)
-
- // But we could set it to something concrete to have it persist.
- c = SetMathRand(c, rand.New(rand.NewSource(thing.UnixNano())))
- r = rand.New(rand.NewSource(thing.UnixNano()))
- So(GetMathRand(c).Int(), ShouldEqual, r.Int())
- So(GetMathRand(c).Int(), ShouldEqual, r.Int())
- })
-
- c = SetTimeNow(c, nil)
- now := time.Now()
- So(GetTimeNow(c), ShouldHappenOnOrAfter, now)
- })
+ Convey("MathRand", func() {
+ r := rand.New(rand.NewSource(now.UnixNano()))
+ i := r.Int()
+ // when it's unset it picks the current time every time
+ So(GetMathRand(c).Int(), ShouldEqual, i)
+ So(GetMathRand(c).Int(), ShouldEqual, i)
+
+ // But we could set it to something concrete to have it persist.
+ c = SetMathRand(c, rand.New(rand.NewSource(now.UnixNano())))
+ r = rand.New(rand.NewSource(now.UnixNano()))
+ So(GetMathRand(c).Int(), ShouldEqual, r.Int())
+ So(GetMathRand(c).Int(), ShouldEqual, r.Int())
+ })
})
}
« no previous file with comments | « no previous file | go/src/infra/gae/libs/wrapper/mathrand.go » ('j') | go/src/infra/gae/libs/wrapper/memory/memcache.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698