-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Test for ResourceWarning:unclosed transport #4713
base: master
Are you sure you want to change the base?
Conversation
loop = asyncio.get_event_loop() is failing and I am not sure how to fix it. |
tests/test_resource_warning.py
Outdated
|
||
|
||
def test_ressource_warning(warning_setup): | ||
loop = asyncio.get_event_loop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's failing because it should be in async def
to work. But then, why don't you just do await _test_warning()
?
tests/test_resource_warning.py
Outdated
if last_warning: | ||
await client.close() | ||
raise ResourceWarning(last_warning) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need all this complex logic here? Tests should be simple and not catch errors.
tests/test_resource_warning.py
Outdated
def warning_setup(): | ||
# setup warning | ||
old_func = warnings.showwarning | ||
warnings.showwarning = print_warnings | ||
warnings.simplefilter('default') | ||
|
||
yield | ||
|
||
warnings.showwarning = old_func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified as
def warning_setup(): | |
# setup warning | |
old_func = warnings.showwarning | |
warnings.showwarning = print_warnings | |
warnings.simplefilter('default') | |
yield | |
warnings.showwarning = old_func | |
def warning_setup(monkeypatch): | |
monkeypatch.setattr(warnings, 'showwarning', print_warnings) | |
warnings.simplefilter('default') |
I modified the test but when running through pytest the behavior is different.
|
@spacemanspiff2007 maybe revert the test to normal |
Now it fails as expected |
tests/test_resource_warning.py
Outdated
break | ||
|
||
if now > next_request: | ||
async with client.get('https://heise.de') as resp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use a local server. Here's fixtures that will help you to set up a trusted TLS context while still using real-world SSL: c180800#diff-5d43d8b7848138232c802e32ab023dd3R271-R272
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would I use the fixture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add it as an arg into fixtures that set up a web server and a client and pass as ssl
:
server = await aiohttp_server(app, ssl=ssl_ctx)
conn = aiohttp.TCPConnector(ssl=client_ssl_ctx)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I don't know how to setup a server and use it.
Can't we leave it like this, it seems to be working fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests should work offline. Imagine you're traveling w/o any internet connectivity. You should be able to run this on your laptop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could make a suggestion I'd gladly copy paste it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you don't have to manually copy suggestions, it's better to click Commit suggestion
from the GitHub UI because this way it automatically preserves authorship.
Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Hm - your internal server changes something so the test does not fail any more. |
Hm... https://heise.de responds with |
Sorry - I don't know much about http connections and don't know how to do that. |
@webknjaz : Shouldn't we revert the test to the external server solution? At least then it's failing reproducible and can be fixed. |
This issue is still relevant - how shall we proceed? |
Any update on this, I'm having the same problem. |
The master branch has the reimplementation of client session/connector closing which waits for the actual protocol's |
This comment has been minimized.
This comment has been minimized.
@asvetlov why did you close this? I think it's a good foundation for the regression test we need. |
As you wish. |
|
What do these changes do?
Add a test for
ResourceWarning:unclosed
transportAre there changes in behavior for the user?
None
Related issue number
#4703
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.