Skip to content

Commit 35b55a3

Browse files
alexclaude
andauthored
Fix test_wantWriteError failure on macOS (#1474)
* Fix test_wantWriteError failure on macOS Use Unix domain sockets instead of TCP loopback. On macOS, TCP loopback aggressively auto-tunes buffer sizes and drains the send buffer into the peer's receive buffer nearly instantly, so the send buffer won't stay full long enough for do_handshake() to observe it, resulting in WantReadError instead of the expected WantWriteError. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix RUF061: use context-manager form of pytest.deprecated_call() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bcac7d2 commit 35b55a3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/test_ssl.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SOL_SOCKET,
3838
gaierror,
3939
socket,
40+
socketpair,
4041
)
4142
from sys import getfilesystemencoding, platform
4243
from weakref import ref
@@ -670,7 +671,8 @@ def test_load_client_ca_unicode(
670671
"""
671672
Passing the path as unicode raises a warning but works.
672673
"""
673-
pytest.deprecated_call(context.load_client_ca, ca_file.decode("ascii"))
674+
with pytest.deprecated_call():
675+
context.load_client_ca(ca_file.decode("ascii")) # type: ignore[arg-type]
674676

675677
def test_set_session_id(self, context: Context) -> None:
676678
"""
@@ -705,7 +707,8 @@ def test_set_session_id_unicode(self, context: Context) -> None:
705707
`Context.set_session_id` raises a warning if a unicode string is
706708
passed.
707709
"""
708-
pytest.deprecated_call(context.set_session_id, "abc")
710+
with pytest.deprecated_call():
711+
context.set_session_id("abc") # type: ignore[arg-type]
709712

710713
def test_method(self) -> None:
711714
"""
@@ -3070,7 +3073,14 @@ def test_wantWriteError(self) -> None:
30703073
`OpenSSL.SSL.WantWriteError` if writing to the connection's BIO
30713074
fail indicating a should-write state.
30723075
"""
3073-
client_socket, _ = socket_pair()
3076+
# Use Unix domain sockets rather than TCP loopback. On macOS,
3077+
# TCP loopback aggressively auto-tunes buffer sizes and drains
3078+
# the send buffer into the peer's receive buffer nearly
3079+
# instantly, so the send buffer won't stay full long enough
3080+
# for do_handshake() to observe it.
3081+
client_socket, peer = socketpair()
3082+
client_socket.setblocking(False)
3083+
peer.setblocking(False)
30743084
# Fill up the client's send buffer so Connection won't be able to write
30753085
# anything. Start by sending larger chunks (Windows Socket I/O is slow)
30763086
# and continue by writing a single byte at a time so we can be sure we

0 commit comments

Comments
 (0)