Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several tweaks to the testing clock. #3

Merged
merged 2 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
One of the Juju tests was failing.
We assumed that doing WaitAdvance(0,0,0) was valid. However, that
triggers final before next, which means we don't see the 'everything is
ok' event. Instead put one final check during WaitAdvance that we got
what we wanted.
  • Loading branch information
jameinel committed Feb 4, 2019
commit 7d6126f6663ece97615470fd3dd93285785c7ad5
4 changes: 4 additions & 0 deletions testclock/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (clock *Clock) WaitAdvance(d, w time.Duration, n int) error {
for {
select {
case <-finalTimeout:
if clock.hasNWaiters(n) {
clock.Advance(d)
return nil
}
clock.mu.Lock()
got := len(clock.waiting)
var stacks string
Expand Down
6 changes: 5 additions & 1 deletion testclock/clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ func (*clockSuite) TestWaitAdvance(c *gc.C) {
t0 := time.Now()
cl := testclock.NewClock(t0)

// It is legal to just say 'nothing is waiting'
err := cl.WaitAdvance(0, 0, 0)
c.Check(err, jc.ErrorIsNil)

// Test that no timers errors out.
err := cl.WaitAdvance(time.Millisecond, 10*time.Millisecond, 1)
err = cl.WaitAdvance(time.Millisecond, 10*time.Millisecond, 1)
c.Check(err, gc.ErrorMatches, "got 0 timers added after waiting 10ms: wanted 1, stacks:\n")

// Test that a timer doesn't error.
Expand Down