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

Test hangs with Redis backend in Starlette/FastAPI #44

Closed
Buuntu opened this issue Mar 29, 2021 · 4 comments
Closed

Test hangs with Redis backend in Starlette/FastAPI #44

Buuntu opened this issue Mar 29, 2021 · 4 comments

Comments

@Buuntu
Copy link
Contributor

Buuntu commented Mar 29, 2021

Using the testing example from the Starlette docs with a route that uses a Redis websocket just hangs indefinitely:

def test_websocket(client):
        with client.websocket_connect("/ws") as websocket:
            websocket.send_text("Hello WebSocket")
            data = websocket.receive_text()
            assert data == "Hello WebSocket"

this however, works fine:

def test_websocket(client):
        with client.websocket_connect("/ws") as websocket:
            assert True

maybe it's related to this #2 (comment) and #42?

I think it's the same with a memory backend. Has anyone successfully tested a Starlette websocket route?

UPDATE: I tried running ./scripts/test locally from the broadcaster directory and it actually hangs for me on the redis test. Anyone else getting that?

@Buuntu Buuntu changed the title Error when testing Redis backend in Starlette Error when testing Redis backend in Starlette/FastAPI Mar 29, 2021
@Buuntu Buuntu changed the title Error when testing Redis backend in Starlette/FastAPI Test hangs with Redis backend in Starlette/FastAPI Mar 29, 2021
@justinepdevasia
Copy link

justinepdevasia commented Nov 1, 2021

@Buuntu I too have got the same issue on testing ./scripts/test for redis. on examining with redis-cli monitor command inside redis, it is seen that publishing to the channel happens before subscribe and it is waiting forever to get published data.The test examined is

@pytest.mark.asyncio
async def test_redis():
    async with Broadcast("redis://localhost:6379") as broadcast:
        async with broadcast.subscribe("chatroom") as subscriber:
            await broadcast.publish("chatroom", "hello")
            event = await subscriber.get()
            assert event.channel == "chatroom"
            assert event.message == "hello"

Redis cli output

Screenshot 2021-11-01 at 3 23 28 PM

But it was working after adding a minimal delay before publish

import asyncio

@pytest.mark.asyncio
async def test_redis():
    async with Broadcast("redis://localhost:6379") as broadcast:
        async with broadcast.subscribe("chatroom") as subscriber:
            await asyncio.sleep(0.01)
            await broadcast.publish("chatroom", "hello")
            event = await subscriber.get()
            assert event.channel == "chatroom"
            assert event.message == "hello"

Redis cli output

Screenshot 2021-11-01 at 3 28 28 PM

In this case subscribe occur before publish and the test got passed. (looks like a Heisunbug)

@alex-oleshkevich
Copy link
Member

We changed the underlying Redis library to redis-py. Can you please re-test if the issue is still there?

@alex-oleshkevich
Copy link
Member

It does not hang either in tests nor in the example. I think this issue is fixed.
Feel free to reopen.

@alex-oleshkevich
Copy link
Member

Closing it as stalled. Feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants