Switch to pyserial-asyncio-fast to fix event loop being blocked - #34
Conversation
|
I'm not sure why its passing locally but failing in the CI |
It fails locally on my machine with the same error. Python 3.12 on Fedora 39. |
|
ah, the test is skipped on darwin, which is what I'm testing on |
|
It might be due to this change pyserial/pyserial-asyncio@7987e6e which was never released in pyserial before it went unmaintained but made it into pyserial-asyncio-fast |
|
I'm not 100% sure what the test is trying to test here. We really need to get this fixed because sleep in the event loop is going to be blocked in HA 2023.7.x which will break this integration (its the last one to be fixed) |
The test uses a socket serial device to verify that when an already opened aioraven device is disconnected, attempts to get data raise an exception. It appears that under I can set up a test using socat to see if this change in behavior is specific to socket serial devices, but I don't have time to do it right now. Clearly I would have a biased perspective here, but if |
Its intended to be but since its branched from a later point in after Ideally we fix |
|
If I revert the unreleased pyserial-asyncio commit pyserial/pyserial-asyncio@7987e6e, the tests pass |
|
I think the issue might be that the test is using a socket to mock a serial connection but since that PR now sees |
|
Sadly I don't have the right test setup to be able to move this PR forward. |
|
Okay, it sounds like a change to The intent of the test was to use as much of |
I don't think we can change it because it would likely regress the problems that were solved by that commit which Home Assistant uses for zha. @puddly -- sorry for the ping but I don't know the full history of that commit |
|
We use our own wrapper in zigpy (https://github.com/zigpy/zigpy/blob/150e88c774c062e8321822437bc7101ca26f7dff/zigpy/serial.py#L40) and do not rely on pyserial-asyncio for network communication so you can change whatever is necessary. I'll look more into this. It'd be best to maintain compatibility if possible. The commit was created because pyserial performs a blocking |
|
I believe this may be a bad mixing of diff --git a/test/mock_device.py b/test/mock_device.py
index c9b71ec..50bb30a 100644
--- a/test/mock_device.py
+++ b/test/mock_device.py
@@ -198,18 +198,8 @@ async def mock_device(
return asyncio.wait_for(task, None)
server = await asyncio.start_server(client_connected, host='127.0.0.1')
- try:
+ async with server:
yield server.sockets[0].getsockname()
- finally:
- server.close()
- if not connections:
- return
-
- _, pending = await asyncio.wait(connections, timeout=0.1)
- for task in pending:
- task.cancel()
- if pending:
- await asyncio.wait(pending)I believe the test case now fails because the TCP server is still actually in a listening state when the context manager exits. pyserial-asyncio's current behavior of introducing a 0.2s synchronous block on TCP disconnect may have hidden a cleanup bug. |
|
I switched the test we were having trouble with to use a pty instead of socket serial. Because the windows socket serial didn't work right to begin with, it actually yields better test coverage on Darwin anyway. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #34 +/- ##
=======================================
Coverage 87.14% 87.14%
=======================================
Files 7 7
Lines 809 809
=======================================
Hits 705 705
Misses 104 104 ☔ View full report in Codecov by Sentry. |
fixes #33
related PR home-assistant/core#116635