From 22a1e878dc8587d64f140d42338a5909d558f5a9 Mon Sep 17 00:00:00 2001 From: Guozhang Wu <30565051+zcxsythenew@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:22:53 +0800 Subject: [PATCH 1/4] gh-111347: Remove wrong assertion in test_sendfile --- Lib/test/test_asyncio/test_sendfile.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index 0198da21d77028..7c720a33c4d354 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -470,8 +470,6 @@ def test_sendfile_close_peer_in_the_middle_of_receiving(self): self.assertTrue(1024 <= srv_proto.nbytes < len(self.DATA), srv_proto.nbytes) - self.assertTrue(1024 <= self.file.tell() < len(self.DATA), - self.file.tell()) self.assertTrue(cli_proto.transport.is_closing()) def test_sendfile_fallback_close_peer_in_the_middle_of_receiving(self): From 272ab330629cb6125b10d8e83b1171fa84309d01 Mon Sep 17 00:00:00 2001 From: Guozhang Wu <30565051+zcxsythenew@users.noreply.github.com> Date: Sat, 28 Oct 2023 07:57:34 +0800 Subject: [PATCH 2/4] gh-111347: Remove wrong assertion in test_sendfile --- Lib/test/test_asyncio/test_sendfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index 7c720a33c4d354..6883a0330e7073 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -470,6 +470,10 @@ def test_sendfile_close_peer_in_the_middle_of_receiving(self): self.assertTrue(1024 <= srv_proto.nbytes < len(self.DATA), srv_proto.nbytes) + if sys.platform != 'win32' or \ + not isinstance(self.loop, asyncio.ProactorEventLoop): + self.assertTrue(1024 <= self.file.tell() < len(self.DATA), + self.file.tell()) self.assertTrue(cli_proto.transport.is_closing()) def test_sendfile_fallback_close_peer_in_the_middle_of_receiving(self): From 0e58411c178d75f1d1d55313532a27a5029d8ce1 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 28 Oct 2023 17:57:37 -0700 Subject: [PATCH 3/4] Rewrite condition differently --- Lib/test/test_asyncio/test_sendfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index 6883a0330e7073..722024e4e78e68 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -470,8 +470,8 @@ def test_sendfile_close_peer_in_the_middle_of_receiving(self): self.assertTrue(1024 <= srv_proto.nbytes < len(self.DATA), srv_proto.nbytes) - if sys.platform != 'win32' or \ - not isinstance(self.loop, asyncio.ProactorEventLoop): + if not (sys.platform == 'win32' + and isinstance(self.loop, asyncio.ProactorEventLoop)): self.assertTrue(1024 <= self.file.tell() < len(self.DATA), self.file.tell()) self.assertTrue(cli_proto.transport.is_closing()) From 3f40f8e7bc6423959f4f75dc76449f1241b7e176 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 28 Oct 2023 18:02:30 -0700 Subject: [PATCH 4/4] Add a comment explaining why we skip the assert --- Lib/test/test_asyncio/test_sendfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index 722024e4e78e68..d33ff197bbfa1d 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -472,6 +472,7 @@ def test_sendfile_close_peer_in_the_middle_of_receiving(self): srv_proto.nbytes) if not (sys.platform == 'win32' and isinstance(self.loop, asyncio.ProactorEventLoop)): + # On Windows, Proactor uses transmitFile, which does not update tell() self.assertTrue(1024 <= self.file.tell() < len(self.DATA), self.file.tell()) self.assertTrue(cli_proto.transport.is_closing())