-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
reset woken of outer future after polled #4157
Conversation
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 really understand why it wasn't done like this in #3582.
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.
That looks correct. You think there is a test you can write for this?
It seems not easy to test. If I want to test this, I have to change many fields or structs' visibility. :) |
The other PR had a test that a certain future was not polled more than three times. It seems like a test like that could work here without changing the visibility of anything. |
What I want to test is |
You could test that checking whether it gets polled when some other spawned future gets polled, no? |
78ff17f
to
8f46f0e
Compare
cc @Darksonn @zaharidichev please review the new added test |
// expect ResetFuture.pending_cnt = 1 | ||
// 2. recv message from channel, ResetFuture returns Ready immediately. | ||
// We expect ResetFuture.pending_cnt = 0 | ||
future::ready(()).await; |
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'm guessing you want tokio::task::yield_now
here? Awaiting a future::ready
doesn't actually yield.
@@ -31,6 +31,40 @@ fn assert_at_most_num_polls(rt: Arc<Runtime>, at_most_polls: usize) { | |||
assert!(polls <= at_most_polls); | |||
} | |||
|
|||
fn assert_no_unnecessary_poll(rt: Arc<Runtime>) { |
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.
You don't need to wrap the runtime in an Arc
as its used here.
Please don't force push the PR when you make changes. It's a lot harder to keep track of what changed since I last looked when you do that. |
I see, I was worried about too many commits. |
We squash your PR on merge, so that's not a concern. |
Motivation
Current implementation does not reset woken flag after polling outer future. This results in outer future being polled again and again which is unnecessary when outer future not ready.
Solution
Swap woken flag to false at the start of loop.