mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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.
This commit is contained in:
parent
45398ad512
commit
c9ecd3ee75
2 changed files with 12 additions and 4 deletions
|
@ -27,6 +27,7 @@ import select
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
from test import support
|
||||||
|
|
||||||
if not hasattr(select, "epoll"):
|
if not hasattr(select, "epoll"):
|
||||||
raise unittest.SkipTest("test works only on Linux 2.6")
|
raise unittest.SkipTest("test works only on Linux 2.6")
|
||||||
|
@ -186,10 +187,16 @@ class TestEPoll(unittest.TestCase):
|
||||||
client.sendall(b"Hello!")
|
client.sendall(b"Hello!")
|
||||||
server.sendall(b"world!!!")
|
server.sendall(b"world!!!")
|
||||||
|
|
||||||
|
# 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()
|
now = time.monotonic()
|
||||||
events = ep.poll(1.0, 4)
|
events += ep.poll(1.0, 4)
|
||||||
then = time.monotonic()
|
then = time.monotonic()
|
||||||
self.assertFalse(then - now > 0.01)
|
self.assertFalse(then - now > 0.01)
|
||||||
|
if len(events) >= 2:
|
||||||
|
break
|
||||||
|
|
||||||
expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT),
|
expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT),
|
||||||
(server.fileno(), select.EPOLLIN | select.EPOLLOUT)]
|
(server.fileno(), select.EPOLLIN | select.EPOLLOUT)]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
fix use of poll in test_epoll's test_control_and_wait
|
Loading…
Add table
Add a link
Reference in a new issue