MCPcopy
hub / github.com/pyodide/pyodide / test_socket_send_recv_partial

Function test_socket_send_recv_partial

src/tests/test_python_socket.py:295–324  ·  view source on GitHub ↗

Test partial recv when buffer is smaller than data.

(selenium_nodesock)

Source from the content-addressed store, hash-verified

293
294
295def test_socket_send_recv_partial(selenium_nodesock):
296 """Test partial recv when buffer is smaller than data."""
297 FULL_MESSAGE = b"A" * 1000
298
299 def handler(conn, _addr):
300 conn.recv(1024)
301 conn.sendall(FULL_MESSAGE)
302
303 @run_in_pyodide
304 def run(selenium, host, port, full_message):
305 import socket
306
307 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
308 s.connect((host, port))
309
310 s.sendall(b"start")
311
312 received = b""
313 while len(received) < len(full_message):
314 chunk = s.recv(100)
315 if not chunk:
316 break
317 received += chunk
318
319 s.close()
320 return received.decode()
321
322 with tcp_server(handler) as (host, port):
323 result = run(selenium_nodesock, host, port, FULL_MESSAGE)
324 assert len(result) == len(FULL_MESSAGE)
325
326
327def test_socket_create_multiple(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…