From 9c2a60aef1183d685d30a6ee83a053ec8109a542 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Fri, 17 Mar 2023 21:46:29 +0000 Subject: [PATCH 1/3] fix use of poll in test_epoll's test_control_and_wait This test can fail unnecessarily. In the test we wait for events on two file descriptors. This is done in a single call to select.epoll's poll() function. However, it is valid for the OS to return only one event via poll() and the next via a subsequent call to poll(). This rarely happens, but it can cause the test to fail despite properly functioning polling. Instead, we poll a second time when necessary. Fixes #102795. --- Lib/test/test_epoll.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py index b623852f9eb4ee..d9a9f21df273dd 100644 --- a/Lib/test/test_epoll.py +++ b/Lib/test/test_epoll.py @@ -191,6 +191,14 @@ def test_control_and_wait(self): then = time.monotonic() self.assertFalse(then - now > 0.01) + # we might receive events one at a time + if len(events) < 2: + now = time.monotonic() + events += ep.poll(1.0, 4) + then = time.monotonic() + self.assertFalse(then - now > 0.01) + + expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT), (server.fileno(), select.EPOLLIN | select.EPOLLOUT)] self.assertEqual(sorted(events), sorted(expected)) From 3be00b6d62537b8b873c0724756ea5b9e7af0f50 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 17 Mar 2023 22:00:48 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Tests/2023-03-17-22-00-47.gh-issue-102795.z21EoC.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2023-03-17-22-00-47.gh-issue-102795.z21EoC.rst diff --git a/Misc/NEWS.d/next/Tests/2023-03-17-22-00-47.gh-issue-102795.z21EoC.rst b/Misc/NEWS.d/next/Tests/2023-03-17-22-00-47.gh-issue-102795.z21EoC.rst new file mode 100644 index 00000000000000..fe2afff91ece7a --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-03-17-22-00-47.gh-issue-102795.z21EoC.rst @@ -0,0 +1 @@ +fix use of poll in test_epoll's test_control_and_wait From 452ecb7cb2019ba1b601643d8f9be096f0bcb657 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Mon, 10 Apr 2023 23:01:49 +0000 Subject: [PATCH 3/3] use test.support.busy_retry to avoid repeating code --- Lib/test/test_epoll.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py index d9a9f21df273dd..c94946a6ae6b7c 100644 --- a/Lib/test/test_epoll.py +++ b/Lib/test/test_epoll.py @@ -27,6 +27,7 @@ import socket import time import unittest +from test import support if not hasattr(select, "epoll"): raise unittest.SkipTest("test works only on Linux 2.6") @@ -186,18 +187,16 @@ def test_control_and_wait(self): client.sendall(b"Hello!") server.sendall(b"world!!!") - now = time.monotonic() - events = ep.poll(1.0, 4) - then = time.monotonic() - self.assertFalse(then - now > 0.01) - - # we might receive events one at a time - if len(events) < 2: + # we might receive events one at a time, necessitating multiple calls to + # poll + events = [] + for _ in support.busy_retry(support.SHORT_TIMEOUT): now = time.monotonic() events += ep.poll(1.0, 4) then = time.monotonic() self.assertFalse(then - now > 0.01) - + if len(events) >= 2: + break expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT), (server.fileno(), select.EPOLLIN | select.EPOLLOUT)] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy