[feat] mock: 增加Sleep函数

pull/3/head
q191201771 3 years ago
parent d70875e877
commit afd2867b88

@ -14,7 +14,6 @@ import (
"time"
)
// TODO(chef): [feat] 增加Clock::Sleep内部用Timer实现等待
// TODO(chef): [feat] 增加Clock::NewTicker
type Clock interface {
@ -24,6 +23,7 @@ type Clock interface {
//
Now() time.Time
NewTimer(d time.Duration) *Timer
Sleep(d time.Duration)
// Add Set ...
//
@ -59,6 +59,10 @@ func (c *stdClock) NewTimer(d time.Duration) *Timer {
}
}
func (c *stdClock) Sleep(d time.Duration) {
time.Sleep(d)
}
func (c *stdClock) Add(d time.Duration) {
// noop
}
@ -95,6 +99,11 @@ func (fc *fakeClock) NewTimer(d time.Duration) *Timer {
return t
}
func (fc *fakeClock) Sleep(d time.Duration) {
// TODO(chef): [feat] 实现和add、set挂钩的Sleep内部用Timer实现等待
// 当前的使用场景都是测试场景直接快速跳过Sleep以及能够满足需求
}
func (fc *fakeClock) Add(d time.Duration) {
fc.mu.Lock()
fc.now = fc.now.Add(d)

@ -135,9 +135,11 @@ func TestRotate(t *testing.T) {
now := time.Now()
nazalog.Clock = mock.NewFakeClock()
defer func() {
nazalog.Clock = mock.NewStdClock()
}()
nazalog.Clock.Set(now.Add(48 * time.Hour))
nazalog.Info("bbb")
nazalog.Clock = mock.NewStdClock()
}
func TestPanic(t *testing.T) {

Loading…
Cancel
Save