Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9ecd3e

Browse files
authored
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.
1 parent 45398ad commit c9ecd3e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Lib/test/test_epoll.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import socket
2828
import time
2929
import unittest
30+
from test import support
3031

3132
if not hasattr(select, "epoll"):
3233
raise unittest.SkipTest("test works only on Linux 2.6")
@@ -186,10 +187,16 @@ def test_control_and_wait(self):
186187
client.sendall(b"Hello!")
187188
server.sendall(b"world!!!")
188189

189-
now = time.monotonic()
190-
events = ep.poll(1.0, 4)
191-
then = time.monotonic()
192-
self.assertFalse(then - now > 0.01)
190+
# we might receive events one at a time, necessitating multiple calls to
191+
# poll
192+
events = []
193+
for _ in support.busy_retry(support.SHORT_TIMEOUT):
194+
now = time.monotonic()
195+
events += ep.poll(1.0, 4)
196+
then = time.monotonic()
197+
self.assertFalse(then - now > 0.01)
198+
if len(events) >= 2:
199+
break
193200

194201
expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT),
195202
(server.fileno(), select.EPOLLIN | select.EPOLLOUT)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix use of poll in test_epoll's test_control_and_wait

0 commit comments

Comments
 (0)