WebSocket connections work with fully unset, partial, and None timeout fields.
(driver: Driver, server_url: URL)
| 836 | indirect=True, |
| 837 | ) |
| 838 | async def test_websocket_client_timeout(driver: Driver, server_url: URL): |
| 839 | """WebSocket connections work with fully unset, partial, and None timeout fields.""" |
| 840 | assert isinstance(driver, WebSocketClientMixin) |
| 841 | |
| 842 | ws_url = server_url.with_scheme("ws") |
| 843 | |
| 844 | # timeout not set, default timeout should apply |
| 845 | request = Request("GET", ws_url) |
| 846 | async with driver.websocket(request) as ws: |
| 847 | await ws.send("quit") |
| 848 | with pytest.raises(WebSocketClosed): |
| 849 | await ws.receive() |
| 850 | |
| 851 | await anyio.sleep(1) |
| 852 | |
| 853 | # timeout is float or none |
| 854 | request = Request("GET", ws_url, timeout=10.0) |
| 855 | async with driver.websocket(request) as ws: |
| 856 | await ws.send("quit") |
| 857 | with pytest.raises(WebSocketClosed): |
| 858 | await ws.receive() |
| 859 | |
| 860 | await anyio.sleep(1) |
| 861 | |
| 862 | # all fields unset, default timeout should apply |
| 863 | request = Request("GET", ws_url, timeout=Timeout()) |
| 864 | async with driver.websocket(request) as ws: |
| 865 | await ws.send("quit") |
| 866 | with pytest.raises(WebSocketClosed): |
| 867 | await ws.receive() |
| 868 | |
| 869 | await anyio.sleep(1) |
| 870 | |
| 871 | # close explicitly set to None (no close timeout) |
| 872 | request = Request("GET", ws_url, timeout=Timeout(close=None)) |
| 873 | async with driver.websocket(request) as ws: |
| 874 | await ws.send("quit") |
| 875 | with pytest.raises(WebSocketClosed): |
| 876 | await ws.receive() |
| 877 | |
| 878 | await anyio.sleep(1) |
| 879 | |
| 880 | |
| 881 | @pytest.mark.parametrize( |