Browse Source

Add `time.sleep(0.1)` in `test_websocket_handle_disconnection` to make test stable

pull/14992/head
Yurii Motov 5 months ago
parent
commit
a754bc1c27
  1. 3
      tests/test_tutorial/test_websockets/test_tutorial003.py

3
tests/test_tutorial/test_websockets/test_tutorial003.py

@ -1,4 +1,5 @@
import importlib
import time
from types import ModuleType
import pytest
@ -42,11 +43,13 @@ def test_websocket_handle_disconnection(client: TestClient):
connection.send_text("Hello from 1234")
data1 = connection.receive_text()
assert data1 == "You wrote: Hello from 1234"
time.sleep(0.01) # Give server time to process broadcast
data2 = connection_two.receive_text()
client1_says = "Client #1234 says: Hello from 1234"
assert data2 == client1_says
data1 = connection.receive_text()
assert data1 == client1_says
connection_two.close()
time.sleep(0.01) # Give server time to process broadcast
data1 = connection.receive_text()
assert data1 == "Client #5678 left the chat"

Loading…
Cancel
Save