summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-01-25 14:01:33 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-01-25 14:01:33 (GMT)
commitf67255ab94742b017697bdedfd4c8eb25dac6f82 (patch)
tree391dc1e1c5a305ae4cc9bccec135a9bb6206e37f /Lib/test
parent635fca9704b102a97233a3af18231a7b649d0169 (diff)
downloadcpython-f67255ab94742b017697bdedfd4c8eb25dac6f82.zip
cpython-f67255ab94742b017697bdedfd4c8eb25dac6f82.tar.gz
cpython-f67255ab94742b017697bdedfd4c8eb25dac6f82.tar.bz2
Issue #20311: asyncio: Add a granularity attribute to BaseEventLoop: maximum
between the resolution of the BaseEventLoop.time() method and the resolution of the selector. The granuarility is used in the scheduler to round time and deadline.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_events.py23
-rw-r--r--Lib/test/test_asyncio/test_selector_events.py4
2 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 21036b5..7a4d698 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1116,6 +1116,29 @@ class EventLoopTestsMixin:
r.close()
w.close()
+ def test_timeout_rounding(self):
+ def _run_once():
+ self.loop._run_once_counter += 1
+ orig_run_once()
+
+ orig_run_once = self.loop._run_once
+ self.loop._run_once_counter = 0
+ self.loop._run_once = _run_once
+ calls = []
+
+ @tasks.coroutine
+ def wait():
+ loop = self.loop
+ calls.append(loop._run_once_counter)
+ yield from tasks.sleep(loop.granularity * 10, loop=loop)
+ calls.append(loop._run_once_counter)
+ yield from tasks.sleep(loop.granularity / 10, loop=loop)
+ calls.append(loop._run_once_counter)
+
+ self.loop.run_until_complete(wait())
+ calls.append(self.loop._run_once_counter)
+ self.assertEqual(calls, [1, 3, 5, 6])
+
class SubprocessTestsMixin:
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
index 38aa766..c0249df 100644
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -39,7 +39,9 @@ def list_to_buffer(l=()):
class BaseSelectorEventLoopTests(unittest.TestCase):
def setUp(self):
- self.loop = TestBaseSelectorEventLoop(unittest.mock.Mock())
+ selector = unittest.mock.Mock()
+ selector.resolution = 1e-3
+ self.loop = TestBaseSelectorEventLoop(selector)
def test_make_socket_transport(self):
m = unittest.mock.Mock()