Test that connecting to a non-listening port raises an error.
(selenium_nodesock)
| 216 | |
| 217 | |
| 218 | def test_socket_connection_refused(selenium_nodesock): |
| 219 | """Test that connecting to a non-listening port raises an error.""" |
| 220 | # Bind to port 0, get the assigned port, then close immediately. |
| 221 | # This gives us a port that is almost certainly not listening. |
| 222 | tmp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 223 | tmp.bind(("127.0.0.1", 0)) |
| 224 | _, port = tmp.getsockname() |
| 225 | tmp.close() |
| 226 | |
| 227 | @run_in_pyodide(packages=["pytest"]) |
| 228 | def run(selenium, port): |
| 229 | import socket |
| 230 | |
| 231 | import pytest |
| 232 | |
| 233 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 234 | with pytest.raises(OSError): |
| 235 | s.connect(("127.0.0.1", port)) |
| 236 | |
| 237 | run(selenium_nodesock, port) |
| 238 | |
| 239 | |
| 240 | def test_socket_recv_after_close(selenium_nodesock): |