MCPcopy
hub / github.com/pyodide/pyodide / test_socket_recv_eof

Function test_socket_recv_eof

src/tests/test_python_socket.py:364–392  ·  view source on GitHub ↗

Test that recv returns b'' after server closes and all data is consumed.

(selenium_nodesock)

Source from the content-addressed store, hash-verified

362
363
364def test_socket_recv_eof(selenium_nodesock):
365 """Test that recv returns b'' after server closes and all data is consumed."""
366
367 def handler(conn, _addr):
368 conn.sendall(b"goodbye")
369 conn.close()
370
371 @run_in_pyodide
372 def run(selenium, host, port):
373 import socket
374 import time
375
376 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
377 s.connect((host, port))
378
379 data = s.recv(1024)
380
381 # Give time for the FIN to arrive
382 time.sleep(1.0)
383
384 eof = s.recv(1024)
385
386 s.close()
387 return (data.decode(), len(eof))
388
389 with tcp_server(handler) as (host, port):
390 result = run(selenium_nodesock, host, port)
391 assert result[0] == "goodbye"
392 assert result[1] == 0
393
394
395def test_socket_send_after_remote_close(selenium_nodesock):

Callers

nothing calls this directly

Calls 2

tcp_serverFunction · 0.85
runFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…