vendor: clockwork v0.1.0

This commit is contained in:
Gyu-Ho Lee
2016-08-16 16:31:10 -07:00
parent 28b797b538
commit 3f0f4bfee7
3 changed files with 17 additions and 9 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