Skip to content

Commit

Permalink
pythongh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallba…
Browse files Browse the repository at this point in the history
…ck_close_peer_in_the_middle_of_receiving (python#98316)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
  • Loading branch information
fancidev and sobolevn authored Oct 17, 2022
1 parent 72c10d3 commit 3e82ad0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Lib/test/test_asyncio/test_sendfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for sendfile functionality."""

import asyncio
import errno
import os
import socket
import sys
Expand Down Expand Up @@ -484,8 +485,17 @@ def sendfile_native(transp, file, offset, count):

srv_proto, cli_proto = self.prepare_sendfile(close_after=1024)
with self.assertRaises(ConnectionError):
self.run_loop(
self.loop.sendfile(cli_proto.transport, self.file))
try:
self.run_loop(
self.loop.sendfile(cli_proto.transport, self.file))
except OSError as e:
# macOS may raise OSError of EPROTOTYPE when writing to a
# socket that is in the process of closing down.
if e.errno == errno.EPROTOTYPE and sys.platform == "darwin":
raise ConnectionError
else:
raise

self.run_loop(srv_proto.done)

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

0 comments on commit 3e82ad0

Please sign in to comment.