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

[TestLoop] Make MessageWithCallback accept future as a result. #12212

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

robin-near
Copy link
Contributor

@robin-near robin-near commented Oct 11, 2024

Previously, MessageWithCallback<T, R> contains T as well as a callback that is a function that accepts an Result<R, AsyncSendError>. And then, AsyncSender<T, R> is simply Sender<MessageWithCallback<T, R>>.

The problem was that in the actix implementation of Sender<MessageWithCallback<T, R>>, because on the actix side when we call .send(msg) it gives us a future of R, we cannot call the callback right away. The solution was to actix::spawn a future that awaits this future of R and then we call the callback.

This was a bad design, because it is actually the sender (code that calls .send_async(...)) who ends up calling actix::spawn, and that panics if the sender was not on an actix thread.

This PR changes that so that MessageWithCallback<T, R> contains a callback that accepts a future of the result. That way, it becomes the responsibility of whoever awaits on the resulting future from .send_async(...) to drive the result future, and there won't be any problems since we don't spawn anything anymore.

Also correct a use case where code in the test was sending a custom MessageWithCallback. This is not supported; changed it to spawning a future on the testloop instead.

@robin-near robin-near requested a review from a team as a code owner October 11, 2024 21:14
Copy link
Contributor

@pugachAG pugachAG left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@robin-near robin-near added this pull request to the merge queue Oct 14, 2024
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 85.36585% with 6 lines in your changes missing coverage. Please review.

Project coverage is 71.85%. Comparing base (16fd9e8) to head (afa4130).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
core/async/src/actix.rs 71.42% 2 Missing ⚠️
core/async/src/functional.rs 0.00% 2 Missing ⚠️
core/async/src/messaging.rs 87.50% 0 Missing and 1 partial ⚠️
...egration-tests/src/test_loop/utils/transactions.rs 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12212      +/-   ##
==========================================
+ Coverage   71.75%   71.85%   +0.09%     
==========================================
  Files         825      827       +2     
  Lines      165822   166639     +817     
  Branches   165822   166639     +817     
==========================================
+ Hits       118993   119732     +739     
- Misses      41634    41691      +57     
- Partials     5195     5216      +21     
Flag Coverage Δ
backward-compatibility 0.17% <0.00%> (-0.01%) ⬇️
db-migration 0.17% <0.00%> (-0.01%) ⬇️
genesis-check 1.25% <0.00%> (-0.01%) ⬇️
integration-tests 38.79% <41.46%> (-0.14%) ⬇️
linux 71.54% <85.36%> (+0.10%) ⬆️
linux-nightly 71.41% <85.36%> (+0.07%) ⬆️
macos 54.60% <73.07%> (+0.22%) ⬆️
pytests 1.57% <0.00%> (-0.01%) ⬇️
sanity-checks 1.37% <0.00%> (-0.01%) ⬇️
unittests 65.65% <80.55%> (+0.13%) ⬆️
upgradability 0.21% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Merged via the queue into near:master with commit e0d9637 Oct 14, 2024
29 of 30 checks passed
@robin-near robin-near deleted the loop1 branch October 14, 2024 23:55
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.

2 participants