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

Add async support #83

Merged
merged 35 commits into from
Aug 3, 2021
Merged

Add async support #83

merged 35 commits into from
Aug 3, 2021

Conversation

kevinheavey
Copy link
Collaborator

Closes #80

Summary of changes:

  • Adds AsyncClient and AsyncToken classes.
  • Refactors sync code so the async code can use it with minimal duplication. No changes to logic or behaviour of sync methods.
  • Adds tests for async methods.
  • Adds async example to the README
  • Adds httpx as a dependency.
  • Fixes test_get_identity which I noticed wasn't testing get_identity. Instead it was redundantly testing get_genesis_hash.
  • Bumps minor version number.

@codecov
Copy link

codecov bot commented Aug 1, 2021

Codecov Report

Merging #83 (2187aad) into master (1e3fdac) will decrease coverage by 0.79%.
The diff coverage is 79.39%.

@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
- Coverage   88.20%   87.41%   -0.80%     
==========================================
  Files          25       32       +7     
  Lines        1450     1955     +505     
==========================================
+ Hits         1279     1709     +430     
- Misses        171      246      +75     

@kevinheavey
Copy link
Collaborator Author

Should be good to run the CI again. By the way, any idea why those two docstrings didn't show up when I ran make lint? I'm pretty sure that command caught similar errors for me before.

Copy link
Owner

@michaelhly michaelhly left a comment

Choose a reason for hiding this comment

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

Hey @kevinheavey. Thank you for contributing. This PR looks great.

I think it would be better if we have clearer boundaries between the old synchronous client and the new async client so that this codebase is easier to maintain.

And that if someone decides to implement a client that supports websockets, they should not be cramming into the existing api.py file nor the existing integration tests.

return resp


class AsyncClient(_ClientCore): # pylint: disable=too-many-public-methods
Copy link
Owner

Choose a reason for hiding this comment

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

Would it be possible to split into three different files?

  • solana/rpc/core.py
  • solana/rpc/api.cpy (old synchornous client)
  • solana/rpc/async_api.py (new async client)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the same spirit, I'll give AsyncToken its own file too



class AsyncHTTPProvider(AsyncBaseProvider, _HTTPProviderCore):
"""Async HTTP provider to interact with the http rpc endpoint."""
Copy link
Owner

Choose a reason for hiding this comment

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

Same here?



@pytest.mark.integration
def test_request_air_drop(stubbed_sender, test_http_client):
def test_request_air_drop(stubbed_sender, test_http_clients):
Copy link
Owner

Choose a reason for hiding this comment

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

Can we test the async client separate from the old client? Having both synchronous and async tests in the same method makes maintenance more difficult.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is possible, but we'll have a lot of duplicated code without a big refactor of the test suite. Plus there are places where we just test that the response the async client received is the same as that of the sync client, and we'll lose that (without more refactoring).

To get this over the line I'll just duplicate all the old pre-async tests and make async versions of them. Your call if that's what you want

Copy link
Owner

@michaelhly michaelhly Aug 2, 2021

Choose a reason for hiding this comment

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

Yes. Duplicate tests are fine, it's just less confusing. We can decide to refactor and reduce duplicates later.

@kevinheavey
Copy link
Collaborator Author

Made those changes.
Extras:

  • Removed pytest-tornasync as a dev dependency. It wasn't doing anything until I added async tests using pytest-asyncio, at which point it started confusing pytest.
  • Fixed typo in tests: reciever -> receiver

@kevinheavey
Copy link
Collaborator Author

Forgot the linters, should work now

@kevinheavey
Copy link
Collaborator Author

Think pylint should be okay now

@michaelhly
Copy link
Owner

Let's just disable R0913: Too many arguments (7/5) (too-many-arguments) for those modules.

https://pylint.readthedocs.io/en/latest/faq.html#is-there-a-way-to-disable-a-message-for-a-particular-module-only

@kevinheavey
Copy link
Collaborator Author

Done. Got a good feeling about this one. Pylint is not complaining about anything I touched

Copy link
Owner

@michaelhly michaelhly left a comment

Choose a reason for hiding this comment

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

Thanks, @kevinheavey. This is great!

@michaelhly michaelhly merged commit f8fc140 into michaelhly:master Aug 3, 2021
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.

Is there a asynchronous version of solana-py?
2 participants