]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_m...
authorfancidev <fancidev@gmail.com>
Mon, 17 Oct 2022 15:45:38 +0000 (23:45 +0800)
committerGitHub <noreply@github.com>
Mon, 17 Oct 2022 15:45:38 +0000 (08:45 -0700)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_asyncio/test_sendfile.py

index a10504b1c4130e38ded29397591ec76afeb3e80b..0198da21d77028b22fd674858903f8cbe284fefb 100644 (file)
@@ -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),