This repository was archived by the owner on May 18, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -249,7 +249,6 @@ func (m *Mock) Ticker(d time.Duration) *Ticker {
249
249
// Timer creates a new instance of Timer.
250
250
func (m * Mock ) Timer (d time.Duration ) * Timer {
251
251
m .mu .Lock ()
252
- defer m .mu .Unlock ()
253
252
ch := make (chan time.Time , 1 )
254
253
t := & Timer {
255
254
C : ch ,
@@ -259,6 +258,8 @@ func (m *Mock) Timer(d time.Duration) *Timer {
259
258
stopped : false ,
260
259
}
261
260
m .timers = append (m .timers , (* internalTimer )(t ))
261
+ m .mu .Unlock ()
262
+ m .runNextTimer (m .now )
262
263
return t
263
264
}
264
265
Original file line number Diff line number Diff line change @@ -195,6 +195,16 @@ func TestClock_Timer_Reset(t *testing.T) {
195
195
}
196
196
}
197
197
198
+ func TestClock_NegativeDuration (t * testing.T ) {
199
+ clock := NewMock ()
200
+ timer := clock .Timer (- time .Second )
201
+ select {
202
+ case <- timer .C :
203
+ default :
204
+ t .Fatal ("timer should have fired immediately" )
205
+ }
206
+ }
207
+
198
208
// Ensure reset can be called immediately after reading channel
199
209
func TestClock_Timer_Reset_Unlock (t * testing.T ) {
200
210
clock := NewMock ()
You can’t perform that action at this time.
0 commit comments