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

Make WebsocketImplProtocol async iterable #2490

Merged
merged 12 commits into from
Sep 20, 2022
Merged

Conversation

ChihweiLHBird
Copy link
Member

@ChihweiLHBird ChihweiLHBird commented Jun 30, 2022

Make websocket object iterable. Will add tests later when the code has been finalized.

Update:
Manual test was okay. Currently we don't have a test client in Sanic that can send and receive WebSocket messages, so it seems impossible to have a test case for this feature at this time.

@codecov
Copy link

codecov bot commented Jun 30, 2022

Codecov Report

Base: 87.844% // Head: 88.425% // Increases project coverage by +0.581% 🎉

Coverage data is based on head (66a9389) compared to base (389363a).
Patch coverage: 83.333% of modified lines in pull request are covered.

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2490       +/-   ##
=============================================
+ Coverage   87.844%   88.425%   +0.581%     
=============================================
  Files           78        78               
  Lines         6466      6471        +5     
  Branches      1247      1247               
=============================================
+ Hits          5680      5722       +42     
+ Misses         560       517       -43     
- Partials       226       232        +6     
Impacted Files Coverage Δ
sanic/server/websockets/impl.py 37.115% <83.333%> (+7.929%) ⬆️
sanic/app.py 88.204% <0.000%> (+0.704%) ⬆️
sanic/server/websockets/frame.py 92.523% <0.000%> (+0.934%) ⬆️
sanic/server/protocols/websocket_protocol.py 73.015% <0.000%> (+3.174%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ChihweiLHBird ChihweiLHBird marked this pull request as ready for review July 1, 2022 17:21
@ChihweiLHBird ChihweiLHBird requested a review from a team as a code owner July 1, 2022 17:21
@Tronic
Copy link
Member

Tronic commented Jul 1, 2022

Still preferring a solution that only uses __aiter__. Don't care which way it is done.

@ChihweiLHBird ChihweiLHBird requested a review from Tronic July 1, 2022 18:05
@ChihweiLHBird
Copy link
Member Author

Still preferring a solution that only uses __aiter__. Don't care which way it is done.

Just removed __anext__, lol.

@Tronic
Copy link
Member

Tronic commented Jul 1, 2022

Thanks for the PR. This is a very useful feature and it helps to have parity with the websockets module. Receive on a closed socket should probably follow that as well, and no-error on clean close seems like the right thing to do anyway. Will approve as is if no-one else comments on that, with the code changes suggested.

@ChihweiLHBird ChihweiLHBird requested a review from Tronic July 1, 2022 19:41
Tronic
Tronic previously approved these changes Jul 1, 2022
ahopkins
ahopkins previously approved these changes Jul 26, 2022
@ahopkins
Copy link
Member

Can you add a test?

@ChihweiLHBird ChihweiLHBird dismissed stale reviews from ahopkins and Tronic via e4023d6 July 26, 2022 19:06
@ChihweiLHBird
Copy link
Member Author

Can you add a test?

Our test client with WebSocket mimic client support was not released so the CI would fail in this PR. Can we do a release or point the version of sanic-testing to the repo?

@ahopkins
Copy link
Member

Ooo nice! Yeah, I'll do that.

@ChihweiLHBird ChihweiLHBird requested a review from a team as a code owner September 20, 2022 18:43
@ahopkins ahopkins merged commit 1650331 into main Sep 20, 2022
@ahopkins ahopkins deleted the zhiwei/ws-async-iterator branch September 20, 2022 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

Async for can be used to iterate over a websocket's incoming messages
3 participants