-
Notifications
You must be signed in to change notification settings - Fork 42
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
implement Clock.NewTimer #108
Conversation
fc5ef42
to
d0250be
Compare
1b53b06
to
40381bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a question..
} | ||
|
||
// AfterFunc is part of the clock.Clock interface. | ||
func (clock *Clock) AfterFunc(d time.Duration, f func()) clock.Timer { | ||
return clock.addAlarm(d, nil, func() { | ||
go f() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could/should we use tomb to manage the lifetime of this goroutine? and the stop method should try to cleanup running routines as well.. could we have a test case for this scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, although I'm open to persuasion. Remember that this implementation is solely for testing purposes, and I it's generally better the less that the tests know about the details of the code (whether the code uses AfterFunc vs After), so the test shouldn't need to change if the code uses AfterFunc (we know when it completes) vs After (it triggers something that happens elsewhere).
And we can't make Stop clean up goroutines because that's not something that the stdlib Timer.Stop method provides - it's something that individual clients can do if they need to.
FWIW AfterFunc is very rarely used in the Juju source code - almost always to just update a local variable or field.
clock: add NewTimer This allows mock clocks to use timers in the usual way. This is associated with a companion branch in juju testing (juju/testing#108) which needs this as a dependency update.
Also fix some issues with the current implementation - it's allowable to call Reset after a timer has expired to make the timer fire again, which wouldn't work with the previous implementation.
40381bc
to
b4d2fed
Compare
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju-testing |
Also fix some issues with the current implementation - it's allowable
to call Reset after a timer has expired to make the timer fire again,
which wouldn't work with the previous implementation.
Note that this will require a dependency update to use juju/utils#242.
(Review request: http://reviews.vapour.ws/r/5372/)