-
Notifications
You must be signed in to change notification settings - Fork 155
Fix: timer_manager:send_after/3 returns an uncancellable timer #2358
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ test() -> | |
| ok = test_cancel_timer_after_expiry(), | ||
| ok = test_erlang_cancel_timer(), | ||
| pong = test_send_after(), | ||
| ok = test_cancel_send_after(), | ||
| ok = test_cancel_send_after_suppresses_message(), | ||
| ok. | ||
|
|
||
| -include("etest.hrl"). | ||
|
|
@@ -73,6 +75,33 @@ test_send_after() -> | |
| timer_manager:send_after(100, self(), ping), | ||
| pong = wait_for_timeout(ping, 5000). | ||
|
|
||
| %% Regression: the reference returned by send_after/3 must be a registered, | ||
|
Collaborator
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. We don't need this comment. I know that some LLM writes them, but this is maintenance debt, once this is merged regression is gone. |
||
| %% cancellable timer. It previously returned a throwaway ref that was never | ||
| %% in the timer table, so cancel_timer/1 always returned false. | ||
| test_cancel_send_after() -> | ||
| ?ASSERT_MATCH(timer_manager:get_timer_refs(), []), | ||
| TimerRef = timer_manager:send_after(60000, self(), test_cancel_send_after), | ||
| ?ASSERT_MATCH(timer_manager:get_timer_refs(), [TimerRef]), | ||
| R = timer_manager:cancel_timer(TimerRef), | ||
| ?ASSERT_TRUE(is_integer(R)), | ||
| ?ASSERT_TRUE(R > 0), | ||
| ?ASSERT_MATCH(timer_manager:get_timer_refs(), []), | ||
| R2 = timer_manager:cancel_timer(TimerRef), | ||
| ?ASSERT_EQUALS(false, R2), | ||
| ok. | ||
|
|
||
| %% Regression: cancelling a send_after/3 timer must actually stop the message | ||
|
Collaborator
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. We don't need this comment. I know that some LLM writes them, but this is maintenance debt, once this is merged regression is gone. |
||
| %% from being delivered. It previously fired regardless of the cancel. | ||
| test_cancel_send_after_suppresses_message() -> | ||
| ?ASSERT_MATCH(timer_manager:get_timer_refs(), []), | ||
| TimerRef = timer_manager:send_after(100, self(), should_not_arrive), | ||
| _ = timer_manager:cancel_timer(TimerRef), | ||
|
Collaborator
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 would force a schedule out before cancelling. "receive after 50 -> ok end" (we don't have erlang:yield/0 in this branch yet). |
||
| receive | ||
| should_not_arrive -> throw(timer_fired_despite_cancel) | ||
| after 500 -> ok | ||
| end, | ||
| ok. | ||
|
|
||
| wait_for_timeout(Msg, Timeout) -> | ||
| receive | ||
| {timeout, _TimerRef, Msg} -> | ||
|
|
||
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.
Can you please make it shorter?