|
|
@@ -32,10 +32,17 @@ func NewRealClock() Clock {
|
|
|
}
|
|
|
|
|
|
// NewFakeClock returns a FakeClock implementation which can be
|
|
|
-// manually advanced through time for testing.
|
|
|
+// manually advanced through time for testing. The initial time of the
|
|
|
+// FakeClock will be an arbitrary non-zero time.
|
|
|
func NewFakeClock() FakeClock {
|
|
|
+ // use a fixture that does not fulfill Time.IsZero()
|
|
|
+ return NewFakeClockAt(time.Date(1984, time.April, 4, 0, 0, 0, 0, time.UTC))
|
|
|
+}
|
|
|
+
|
|
|
+// NewFakeClockAt returns a FakeClock initialised at the given time.Time.
|
|
|
+func NewFakeClockAt(t time.Time) FakeClock {
|
|
|
return &fakeClock{
|
|
|
- l: sync.RWMutex{},
|
|
|
+ time: t,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -117,9 +124,10 @@ func (fc *fakeClock) Sleep(d time.Duration) {
|
|
|
|
|
|
// Time returns the current time of the fakeClock
|
|
|
func (fc *fakeClock) Now() time.Time {
|
|
|
- fc.l.Lock()
|
|
|
- defer fc.l.Unlock()
|
|
|
- return fc.time
|
|
|
+ fc.l.RLock()
|
|
|
+ t := fc.time
|
|
|
+ fc.l.RUnlock()
|
|
|
+ return t
|
|
|
}
|
|
|
|
|
|
// Advance advances fakeClock to a new point in time, ensuring channels from any
|