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

chore(tests): don't use .wait() and use block_on instead #2220

Merged
merged 4 commits into from
Sep 24, 2024

Conversation

mariocynicys
Copy link
Collaborator

Encountered an issue regarding a tokio tcp stream that breaks because it was spawned in a non-tokio runtime (in #1966).

These .wait methods used were using a different runtime - from futures - to run the future, but we could have instead did block_on(fut.compat()) and run it on MM2's tokio runtime.

PRing this on its own to reduce the clutter in #1966 :)

this makes sure we run these waited futures on the same runtime.

this fixes the problem with tokio tcp stream breaking when it's
instantiated from within the .wait() method and not from the tokio
runtime
because we now use tokio's block_on to wait for this method and not futures' wait. this means we will block_on the same runtime recurrsively and panic. So instead of block_on in mock methods, fut.boxed() like the original methods.

the difference between the two impls of the mock is that
the first one ran synchronously and returned an immediately ready future,
the second one creates an non-ready future to be ran asynchronously by the caller.
Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These .wait methods used were using a different runtime - from futures - to run the future, but we could have instead did block_on(fut.compat()) and run it on MM2's tokio runtime.

This is hard to maintain manually. I would create clippy rule and let the clippy do the work for us.

Creating clippy.toml with this rule should make that work:

[[disallowed-methods]]
path = "futures::future::Future::wait"
replacement = "common::block_on_f01"
reason = "Use the default KDF async executor."

mm2src/common/common.rs Outdated Show resolved Hide resolved
mm2src/common/common.rs Outdated Show resolved Hide resolved
mm2src/common/common.rs Show resolved Hide resolved
@mariocynicys
Copy link
Collaborator Author

🪄 image

doc comments & magic clippy rule :O
shamardy
shamardy previously approved these changes Sep 24, 2024
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix conflicts :)

@shamardy shamardy merged commit 5c324f2 into dev Sep 24, 2024
22 of 26 checks passed
@shamardy shamardy deleted the wait-to-block-on branch September 24, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants