Skip to content

Commit 3e82ad0

Browse files
fancidevsobolevn
andauthored
gh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_middle_of_receiving (#98316)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent 72c10d3 commit 3e82ad0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Lib/test/test_asyncio/test_sendfile.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for sendfile functionality."""
22

33
import asyncio
4+
import errno
45
import os
56
import socket
67
import sys
@@ -484,8 +485,17 @@ def sendfile_native(transp, file, offset, count):
484485

485486
srv_proto, cli_proto = self.prepare_sendfile(close_after=1024)
486487
with self.assertRaises(ConnectionError):
487-
self.run_loop(
488-
self.loop.sendfile(cli_proto.transport, self.file))
488+
try:
489+
self.run_loop(
490+
self.loop.sendfile(cli_proto.transport, self.file))
491+
except OSError as e:
492+
# macOS may raise OSError of EPROTOTYPE when writing to a
493+
# socket that is in the process of closing down.
494+
if e.errno == errno.EPROTOTYPE and sys.platform == "darwin":
495+
raise ConnectionError
496+
else:
497+
raise
498+
489499
self.run_loop(srv_proto.done)
490500

491501
self.assertTrue(1024 <= srv_proto.nbytes < len(self.DATA),

0 commit comments

Comments
 (0)