From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 18 Oct 2022 15:21:58 +0000 (-0700) Subject: [3.11] gh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_i... X-Git-Tag: v3.11.1~266 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0bba980c5f67e72e8fe4803957ac82748d3b483e;p=thirdparty%2FPython%2Fcpython.git [3.11] gh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_middle_of_receiving (GH-98316) (#98357) Co-authored-by: Nikita Sobolev (cherry picked from commit 3e82ad05b18d004e4d01fdb643344d6a2bf11900) Co-authored-by: fancidev --- diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index a10504b1c413..0198da21d770 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -1,6 +1,7 @@ """Tests for sendfile functionality.""" import asyncio +import errno import os import socket import sys @@ -484,8 +485,17 @@ class SendfileMixin(SendfileBase): 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),