-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Be sure to detach one-shot timer watcher #1178
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,4 +97,30 @@ class Dummy < Fluent::Plugin::TestBase | |
|
||
d1.shutdown; d1.close; d1.terminate | ||
end | ||
|
||
test 'can run at once' do | ||
d1 = Dummy.new | ||
d1.configure(config_element()) | ||
assert !d1.timer_running? | ||
d1.start | ||
assert d1.timer_running? | ||
|
||
counter = 0 | ||
d1.timer_execute(:test, 1, repeat: false) do | ||
counter += 1 | ||
end | ||
|
||
watchers = d1._event_loop.watchers.reject {|w| w.is_a?(Fluent::PluginHelper::EventLoop::DefaultWatcher) } | ||
assert_equal(1, watchers.size) | ||
assert(watchers.first.attached?) | ||
|
||
sleep 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This waiting_assertion = true
waiting_timer = true
counter = 0
d1.timer_execute(:test, 1, repeat: false) do
sleep 0.1 while waiting_assertion
counter += 1
waiting_timer = false
end
# assertions about watchers here
waiting_assertion = false
sleep 0.1 while waiting_timer
assert_equal(1, counter)
# rest of assertions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for sample code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've pushed a change for this comment. |
||
|
||
assert_equal(1, counter) | ||
assert_false(watchers.first.attached?) | ||
watchers = d1._event_loop.watchers.reject {|w| w.is_a?(Fluent::PluginHelper::EventLoop::DefaultWatcher) } | ||
assert_equal(0, watchers.size) | ||
|
||
d1.shutdown; d1.close; d1.terminate | ||
end | ||
end |
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.
Is
@repeating
an instance variable ofTimerWatcher
?I think it's too internal to use it, and it looks too fragile.
We should store
repeat
into our own instance variable in#initialize
and use it.