[Python-checkins] gh-102795: Fix use of poll in test_epoll's test_control_and_wait (#102796)
vstinner
webhook-mailer at python.org
Thu May 4 10:38:45 EDT 2023
https://github.com/python/cpython/commit/c9ecd3ee75b472bb0a7538e0288c5cfea146da83
commit: c9ecd3ee75b472bb0a7538e0288c5cfea146da83
branch: main
author: Kevin Krakauer <kevinGC at users.noreply.github.com>
committer: vstinner <vstinner at python.org>
date: 2023-05-04T14:38:20Z
summary:
gh-102795: Fix use of poll in test_epoll's test_control_and_wait (#102796)
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.
files:
A Misc/NEWS.d/next/Tests/2023-03-17-22-00-47.gh-issue-102795.z21EoC.rst
M Lib/test/test_epoll.py
diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py
index b623852f9eb4..c94946a6ae6b 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,10 +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, 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)]
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 000000000000..fe2afff91ece
--- /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
More information about the Python-checkins
mailing list