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

tests: Replace deprecated asynctest with manual TCP socket in Thread #369

Merged
merged 5 commits into from
Apr 8, 2023

Conversation

MarijnS95
Copy link
Contributor

Depends on #361 and #365
For #305

asynctest is unmaintained and deprecated yet there appears to be no clean replacement to mock the async methods of an asyncio client socket, as previously passed to asyncio.open_connection(). Instead of inventing a complicated asyncio solution around this, create and bind a socket (so that we know the randomly chosen open port upfront) and accept a single client within a Thread. This temporary Thread closes the connection and can later be join()ed when the test is over to make sure it has finalized and exited.

tests/test_tcp_models.py Fixed Show fixed Hide fixed
tests/test_tcp_models.py Outdated Show resolved Hide resolved
@klaasnicolaas
Copy link
Owner

Time to rebase 😉

…read`

`asynctest` is unmaintained and deprecated yet there appears to be no
clean replacement to mock the `async` methods of an `asyncio` client
socket, as previously passed to `asyncio.open_connection()`.  Instead of
inventing a complicated `asyncio` solution around this, create and bind
a `socket` (so that we know the randomly chosen open port upfront) and
accept a single client within a `Thread`.  This temporary `Thread`
closes the connection and can later be `join()`ed when the test is over
to make sure it has finalized and exited.
The client only connects to `localhost` after all, no need to bind all
interfaces.
@klaasnicolaas klaasnicolaas added the refactor Improvement of existing code, not introducing new features. label Apr 7, 2023
@codecov
Copy link

codecov bot commented Apr 8, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (b630a39) 100.00% compared to head (3f7cec3) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #369   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          343       341    -2     
  Branches        54        54           
=========================================
- Hits           343       341    -2     
Impacted Files Coverage Δ
omnikinverter/omnikinverter.py 100.00% <100.00%> (ø)

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 in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@MarijnS95 MarijnS95 marked this pull request as ready for review April 8, 2023 09:04
Copy link
Owner

@klaasnicolaas klaasnicolaas left a comment

Choose a reason for hiding this comment

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

✅ LGTM

@klaasnicolaas klaasnicolaas merged commit efcd826 into klaasnicolaas:main Apr 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2023
@MarijnS95 MarijnS95 deleted the replace-asynctest branch April 10, 2023 14:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
refactor Improvement of existing code, not introducing new features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants