Skip to content

Commit

Permalink
Merge pull request #10 from hpidcock/time-dilation
Browse files Browse the repository at this point in the history
Remove panic and test advancing after timer fires but not sent.
  • Loading branch information
hpidcock authored Aug 8, 2022
2 parents 68a2376 + 95c94d1 commit f18956f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion testclock/dilated.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (t *dilatedWallTimer) run() {
t.offset = newOffset
stopped := t.timer.Stop()
if !stopped {
panic("stopped timer but still running")
continue
}
realNow := time.Now()
dialatedNow := dilateTime(t.dc.epoch, realNow, t.dc.realSecondDuration, t.offset)
Expand Down
24 changes: 22 additions & 2 deletions testclock/dilated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (*dilatedClockSuite) TestReset(c *gc.C) {
select {
case <-a.Chan():
case <-time.After(shortWait):
c.Fatal("clock did not fire")
c.Fatal("timer did not fire")
}
for i := 0; i < 3; i++ {
if runtime.NumGoroutine() == numGo {
Expand All @@ -192,7 +192,27 @@ func (*dilatedClockSuite) TestStopReset(c *gc.C) {
select {
case <-a.Chan():
case <-time.After(shortWait):
c.Fatal("clock did not fire")
c.Fatal("timer did not fire")
}
for i := 0; i < 3; i++ {
if runtime.NumGoroutine() == numGo {
break
}
time.Sleep(shortWait)
}
c.Assert(runtime.NumGoroutine(), gc.Equals, numGo, gc.Commentf("clock goroutine still running"))
}

func (*dilatedClockSuite) TestAdvanceAlreadyFired(c *gc.C) {
numGo := runtime.NumGoroutine()
cl := testclock.NewDilatedWallClock(time.Second)
t := cl.NewTimer(time.Millisecond)
time.Sleep(shortWait)
cl.Advance(time.Second)
select {
case <-t.Chan():
case <-time.After(shortWait):
c.Fatal("timer did not fire")
}
for i := 0; i < 3; i++ {
if runtime.NumGoroutine() == numGo {
Expand Down

0 comments on commit f18956f

Please sign in to comment.