diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-21 00:48:28 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-21 00:48:28 (GMT) |
commit | 11da8e24ba1090b9d55f3451345f0724055f125f (patch) | |
tree | 37f6cbbf807c8b44934990b25c13fe05055431b6 /Lib/test/test_selectors.py | |
parent | 09354fd606409aea1270474270eb8a9396bb477e (diff) | |
download | cpython-11da8e24ba1090b9d55f3451345f0724055f125f.zip cpython-11da8e24ba1090b9d55f3451345f0724055f125f.tar.gz cpython-11da8e24ba1090b9d55f3451345f0724055f125f.tar.bz2 |
Issue #20311: selector.PollSelector.select() now rounds the timeout away from
zero, instead of rounding towards zero. For example, a timeout of one
microsecond is now rounded to one millisecond, instead of being rounded to
zero.
Move also a test in test_epoll which was moved by my previous merge.
Diffstat (limited to 'Lib/test/test_selectors.py')
-rw-r--r-- | Lib/test/test_selectors.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py index 34edd76..d306aef 100644 --- a/Lib/test/test_selectors.py +++ b/Lib/test/test_selectors.py @@ -5,7 +5,7 @@ import selectors import signal import socket from test import support -from time import sleep +from time import sleep, perf_counter import unittest import unittest.mock try: @@ -363,6 +363,22 @@ class BaseSelectorTestCase(unittest.TestCase): self.assertFalse(s.select(2)) self.assertLess(time() - t, 2.5) + def test_timeout_rounding(self): + # Issue #20311: Timeout must be rounded away from zero to wait *at + # least* timeout seconds. For example, epoll_wait() has a resolution of + # 1 ms (10^-3), epoll.select(0.0001) must wait 1 ms, not 0 ms. + s = self.SELECTOR() + self.addCleanup(s.close) + + rd, wr = self.make_socketpair() + s.register(rd, selectors.EVENT_READ) + + for timeout in (1e-2, 1e-3, 1e-4): + t0 = perf_counter() + s.select(timeout) + dt = perf_counter() - t0 + self.assertGreaterEqual(dt, timeout) + class ScalableSelectorMixIn: |