Closed samupl closed 1 year ago
Hmmm. Good report.
What happens if you construct the consumer inside the test method rathe than passing it in as a fixture?
@carltongibson This doesn't seem to help, tests fail with the same error.
To make testing easier, I added github actions to my reproduction repo so that I can test various workarounds through pull requests.
You can see the build failing here: https://github.com/samupl/channels-redis-asyncio-pytest-reproduce/pull/1
OK, thanks — that makes the test easier to read if nothing else. (I was just wondering if something about being a pytest fixture was interfering).
If both connect and disconnect methods are commented out, the tests pass just fine.
Does it block on connect
and disconnect
, or just the one of them? (You say group_discard
in the issue title). Update: CI shows it blocking on the connect
call
And just to check, it works in an application, but fails in the test yes? (If I'm reading you correctly...?)
Did you try calling super()
(which actually sends the self.accept()
message)? 🤔
I think you're right - that call to super()
actually seems to make the tests pass, and the app to work correctly.
It was my mistake, because while the whole app generally seemed to work, I must have failed to test this particular consumer. I made the app on my reproduction repo work and tested it with websocat
only to discover that it never went past the websocket handshake.
I added super()
, which calls accept()
as you said and it seems the issue is resolved: https://github.com/samupl/channels-redis-asyncio-pytest-reproduce/pull/2
Although in the "real" app I'm working on it seems that there is an await self.accept()
in the connect method, so I need to debug it further and come back with a better reproduction
OK, I'm going to close for now. Please follow-up if you find more and it's an issue in Channels — we can happily re-open.
Summary
I was working on a legacy project that used
channels==2.4.0
andchannels-redis==2.4.2
- I decided it was about time to update the packages.After updating, obviously a lot of tests failed. I managed to fix them all except this one. I tried to narrow it down to a minimal reproduction as much as possible.
If a consumer does something like this:
And we have a simple pytest test that verifies this consumer:
pytest with pytest-asyncio isn't able to run simple tests that verify this consumer - the tests fail with a
TimeoutError
.If both
connect
anddisconnect
methods are commented out, the tests pass just fine.Repository with reproduction: https://github.com/samupl/channels-redis-asyncio-pytest-reproduce
OS
Docker,
python:3.11-slim
image,Linux 866362d15f23 6.2.8-200.fc37.x86_64
.Seems to relate to any linux distro, not sure about other platforms though.
Pip freeze
Expected vs actual
TimeoutError
, they only work when connect() and disconnect() get removedPlease also try and include, if you can:
How you're running Channels
Irrelevant, happens in tests
Console logs and full tracebacks of any errors