Skip to content

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

Merged
shamardy merged 4 commits intodevfrom
wait-to-block-on
Sep 24, 2024
Merged

chore(tests): don't use .wait() and use block_on instead#2220
shamardy merged 4 commits intodevfrom
wait-to-block-on

Conversation

@mariocynicys
Copy link
Copy Markdown
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
Copy Markdown

@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."

@mariocynicys
Copy link
Copy Markdown
Collaborator Author

🪄 image

doc comments & magic clippy rule :O
shamardy
shamardy previously approved these changes Sep 24, 2024
Copy link
Copy Markdown
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
@shamardy shamardy deleted the wait-to-block-on branch September 24, 2024 08:56
dimxy pushed a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy pushed a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy pushed a commit that referenced this pull request Oct 17, 2024
* dev:
  fix(cosmos): fix tx broadcasting error (#2238)
  chore(solana): remove solana implementation (#2239)
  chore(cli): remove leftover subcommands from help message (#2235)
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants