Skip to content

Commit 4c66919

Browse files
committed
Test selector thread with closed socket
1 parent 2840e06 commit 4c66919

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

.github/workflows/test.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,13 @@ jobs:
6060
strategy:
6161
fail-fast: false
6262
matrix:
63-
os: [ubuntu-latest]
63+
os: [ubuntu-latest, windows-latest]
6464
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", pypy-3.11]
6565
include:
6666
- os: macos-latest
6767
python-version: "3.9"
6868
- os: macos-latest
6969
python-version: "3.13"
70-
- os: windows-latest
71-
python-version: "3.9"
72-
- os: windows-latest
73-
python-version: "3.13"
7470
runs-on: ${{ matrix.os }}
7571
needs: changed-files
7672
if: |

tests/test_sockets.py

+37
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
getaddrinfo,
4848
getnameinfo,
4949
move_on_after,
50+
sleep,
5051
wait_all_tasks_blocked,
5152
wait_readable,
5253
wait_socket_readable,
@@ -1911,3 +1912,39 @@ async def test_deprecated_wait_socket(anyio_backend_name: str) -> None:
19111912
):
19121913
with move_on_after(0.1):
19131914
await wait_socket_writable(sock)
1915+
1916+
1917+
async def test_selector_thread_closed_socket(anyio_backend_name: str) -> None:
1918+
skip = True
1919+
if anyio_backend_name == "asyncio" and platform.system() == "Windows":
1920+
import asyncio
1921+
1922+
policy = asyncio.get_event_loop_policy()
1923+
if policy.__class__.__name__ == "WindowsProactorEventLoopPolicy":
1924+
skip = False
1925+
1926+
if skip:
1927+
pytest.skip("Selector thread is only used on asyncio/Windows/ProactorEventLoop")
1928+
1929+
async with create_task_group() as tg:
1930+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
1931+
sock.bind(("127.0.0.1", 0))
1932+
sock.listen()
1933+
tg.start_soon(wait_readable, sock)
1934+
await wait_all_tasks_blocked()
1935+
await sleep(1)
1936+
tg.cancel_scope.cancel()
1937+
1938+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_sock:
1939+
server_sock.bind(("127.0.0.1", 0))
1940+
port = server_sock.getsockname()[1]
1941+
server_sock.listen()
1942+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_sock:
1943+
client_sock.connect(("127.0.0.1", port))
1944+
client_sock.sendall(b"Hello, world")
1945+
1946+
conn, addr = server_sock.accept()
1947+
with conn:
1948+
with fail_after(3):
1949+
await wait_readable(conn)
1950+
assert conn.recv(1024) == b"Hello, world"

0 commit comments

Comments
 (0)