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
TestSelector cannot find a previously opened file descriptor. #128
Comments
I ran into this issue, too. It's highly surprising because the existence of Here is a simplified test case, simply based on a background child process: #!/usr/bin/python3
import asyncio
import asynctest
import subprocess
IO = asyncio.get_event_loop()
class SomeTest (asynctest.TestCase):
use_default_loop = True
@classmethod
def setUpClass(cls):
print("setUpClass: starting child process")
coro = asyncio.create_subprocess_shell(
"""
while true; do
echo Foobar
sleep 0.5
done
""",
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT)
cls.proc = IO.run_until_complete(coro)
@classmethod
def tearDownClass(cls):
print("tearDownClass: terminating the process")
cls.proc.terminate()
print("Reading process output until EOF when process terminated:")
while True:
line = IO.run_until_complete(cls.proc.stdout.readline())
print(f"read: {line}")
if len(line) == 0:
break
def test_it(self):
print("Test method test_it: NOOP")
if __name__ == '__main__':
asynctest.main(argv = ["foo_test.py"]) Producing:
|
Martiusweb
added a commit
that referenced
this issue
Jul 16, 2019
Change TestSelector._fd_to_key from a extended copy of TestSelector._selector._fd_to_key to a view on TestSelector._selector._fd_to_key plus the test-part extension. As a result, there is no need to update TestSelector._fd_to_key when TestSelector._selector._fd_to_key is modified. fix #128
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @Martiusweb
First, thanks a lot for the library. We use it in my company to test our asynchronous library and it is so helpful. I encountered an issue using asynctest 0.13.0 with python 3.7.3. Here is the
description.
Issue
I want to use the same http session during all my tests. To do so I open it in
setUpClass
and then just keep it in my tests. However it results in a desynchronisation betweenTestSelector._fd_to_key
andTestSelector._selector._fd_to_key
becausecls.loop._selector
is different betweensetUpClass
and a regular test (patched inTestCase._patch_loop
).In my example I use aiohttp to ease the reading but it is not meaningful here because the issue seems to be related to the underlying socket.
Steps to reproduce
The testcase I use.
Here are the actual steps I use to reproduce the issue. Note that some parts have been eluded (virtualenv creation). If necessary I can provide a more complete list of steps.
Below is the complete stack trace.
It has also been reproduced with python 3.5.7 or asynctest 0.12.4
Fix
I have taken a look at the issue and my first idea was to copy the
_fd_to_key
dict inTestSelector.__init__
(cf. below) . However it does not prevent a future desynchronization between the two. Typically,asyncio.BaseSelectorEventLoop._sock_connect
defines a callback that unregister the file descriptor from the original selector and would leaveTestSelector._fd_to_key
untouched.So I guess the fix may require some deeper change in the library. Would it be possible for you to take a look at it. Thanks a lot.
The text was updated successfully, but these errors were encountered: