updating github.com/jonboulle/clockwork to v0.1.0

This commit is contained in:
Davanum Srinivas
2019-06-14 11:02:22 -04:00
parent d04014a208
commit db35f59e27
11 changed files with 36 additions and 20 deletions

View File

@@ -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