aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_udp_buffer.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/tests/test_udp_buffer.py')
-rw-r--r--packages/meshbay-node/tests/test_udp_buffer.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/meshbay-node/tests/test_udp_buffer.py b/packages/meshbay-node/tests/test_udp_buffer.py
new file mode 100644
index 0000000..2159663
--- /dev/null
+++ b/packages/meshbay-node/tests/test_udp_buffer.py
@@ -0,0 +1,38 @@
+"""
+The node's ICE sockets ask for a receive buffer that holds an upload's window.
+
+Measured on a node in service: during a 200 MB upload from a browser 22 ms
+away the node's machine dropped 2460 of 264000 datagrams at the socket
+(`Udp6RcvbufErrors`), with a buffer of 512 KB, and the upload ran at 6.4 MB/s.
+The browser keeps 32 chunks of 48 KB in flight, 1.5 MB, and the kernel counts
+about twice the bytes it holds.
+"""
+
+import socket
+
+import aioice
+import pytest
+from meshbay_node.transport.webrtc import udp_buffer
+
+
+def test_the_request_covers_what_an_upload_keeps_in_flight():
+ in_flight = 32 * 48 * 1024
+ assert udp_buffer.WANTED >= 2 * in_flight
+ assert aioice.turn.UDP_SOCKET_BUFFER_SIZE == udp_buffer.WANTED
+
+
+@pytest.mark.asyncio
+async def test_a_gathered_socket_gets_what_the_kernel_allows():
+ """aioice reads the constant when it gathers, not when it is imported: the
+ socket of a real candidate has the buffer, up to the machine's ceiling."""
+ conn = aioice.Connection(ice_controlling=True)
+ try:
+ await conn.gather_candidates()
+ sizes = [p.transport.get_extra_info("socket").getsockopt(
+ socket.SOL_SOCKET, socket.SO_RCVBUF)
+ for p in conn._protocols]
+ assert sizes, "no candidate was gathered"
+ assert min(sizes) == udp_buffer.granted()
+ assert min(sizes) > 262144, "the machine grants no more than aioice asked before"
+ finally:
+ await conn.close()