Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/test_mqtt_tls_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,19 @@ def _wrap_tls_socketpair(tmp_path, proxy: MqttTlsProxy) -> tuple[ssl.SSLSocket,
return robot, server


def _assert_peer_closed(sock: socket.socket) -> None:
"""Assert the peer saw the proxy end the connection.

A plain socket reads EOF. A TLS socket was shut down without a close_notify, so
depending on timing its read returns EOF or raises SSLEOFError, or the TLS layer's
own write (for example a session-ticket ack) fails with EPIPE / ECONNRESET.
"""
try:
assert sock.recv(1) == b""
except (ssl.SSLEOFError, BrokenPipeError, ConnectionResetError):
assert isinstance(sock, ssl.SSLSocket)


@pytest.mark.parametrize("tls", [False, True], ids=["plain", "tls"])
def test_close_conn_endpoints_wakes_relay_threads_blocked_in_recv(tmp_path, tls: bool) -> None:
proxy = _teardown_test_proxy(tmp_path)
Expand Down Expand Up @@ -1933,7 +1946,7 @@ def test_close_conn_endpoints_wakes_relay_threads_blocked_in_recv(tmp_path, tls:
assert not thread.is_alive()
assert errors == []
assert broker.recv(1) == b""
assert robot.recv(1) == b""
_assert_peer_closed(robot)
finally:
proxy.stop()
for sock in (robot, broker, *held):
Expand Down