bpo-41804: Enhance test_epoll.test_control_and_wait() (GH-23795)
Use shorter timeout and replace send() with sendall().
This commit is contained in:
parent
b32d8b4f9b
commit
79782fe4f8
|
@ -160,44 +160,42 @@ class TestEPoll(unittest.TestCase):
|
||||||
self.fail("epoll on closed fd didn't raise EBADF")
|
self.fail("epoll on closed fd didn't raise EBADF")
|
||||||
|
|
||||||
def test_control_and_wait(self):
|
def test_control_and_wait(self):
|
||||||
|
# create the epoll object
|
||||||
client, server = self._connected_pair()
|
client, server = self._connected_pair()
|
||||||
|
|
||||||
ep = select.epoll(16)
|
ep = select.epoll(16)
|
||||||
ep.register(server.fileno(),
|
ep.register(server.fileno(),
|
||||||
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
|
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
|
||||||
ep.register(client.fileno(),
|
ep.register(client.fileno(),
|
||||||
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
|
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
|
||||||
|
|
||||||
|
# EPOLLOUT
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
events = ep.poll(1, 4)
|
events = ep.poll(1, 4)
|
||||||
then = time.monotonic()
|
then = time.monotonic()
|
||||||
self.assertFalse(then - now > 0.1, then - now)
|
self.assertFalse(then - now > 0.1, then - now)
|
||||||
|
|
||||||
events.sort()
|
|
||||||
expected = [(client.fileno(), select.EPOLLOUT),
|
expected = [(client.fileno(), select.EPOLLOUT),
|
||||||
(server.fileno(), select.EPOLLOUT)]
|
(server.fileno(), select.EPOLLOUT)]
|
||||||
expected.sort()
|
self.assertEqual(sorted(events), sorted(expected))
|
||||||
|
|
||||||
self.assertEqual(events, expected)
|
# no event
|
||||||
|
events = ep.poll(timeout=0.1, maxevents=4)
|
||||||
events = ep.poll(timeout=2.1, maxevents=4)
|
|
||||||
self.assertFalse(events)
|
self.assertFalse(events)
|
||||||
|
|
||||||
client.send(b"Hello!")
|
# send: EPOLLIN and EPOLLOUT
|
||||||
server.send(b"world!!!")
|
client.sendall(b"Hello!")
|
||||||
|
server.sendall(b"world!!!")
|
||||||
|
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
events = ep.poll(1, 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)
|
||||||
|
|
||||||
events.sort()
|
|
||||||
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)]
|
||||||
expected.sort()
|
self.assertEqual(sorted(events), sorted(expected))
|
||||||
|
|
||||||
self.assertEqual(events, expected)
|
|
||||||
|
|
||||||
|
# unregister, modify
|
||||||
ep.unregister(client.fileno())
|
ep.unregister(client.fileno())
|
||||||
ep.modify(server.fileno(), select.EPOLLOUT)
|
ep.modify(server.fileno(), select.EPOLLOUT)
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
|
|
Loading…
Reference in New Issue