summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_timeouts.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncio/test_timeouts.py')
-rw-r--r--Lib/test/test_asyncio/test_timeouts.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_timeouts.py b/Lib/test/test_asyncio/test_timeouts.py
index ef1ab0a..3a54297 100644
--- a/Lib/test/test_asyncio/test_timeouts.py
+++ b/Lib/test/test_asyncio/test_timeouts.py
@@ -106,6 +106,30 @@ class TimeoutTests(unittest.IsolatedAsyncioTestCase):
self.assertLess(t1-t0, 2)
self.assertTrue(t0 <= cm.when() <= t1)
+ async def test_timeout_zero_sleep_zero(self):
+ loop = asyncio.get_running_loop()
+ t0 = loop.time()
+ with self.assertRaises(TimeoutError):
+ async with asyncio.timeout(0) as cm:
+ await asyncio.sleep(0)
+ t1 = loop.time()
+ self.assertTrue(cm.expired())
+ # 2 sec for slow CI boxes
+ self.assertLess(t1-t0, 2)
+ self.assertTrue(t0 <= cm.when() <= t1)
+
+ async def test_timeout_in_the_past_sleep_zero(self):
+ loop = asyncio.get_running_loop()
+ t0 = loop.time()
+ with self.assertRaises(TimeoutError):
+ async with asyncio.timeout(-11) as cm:
+ await asyncio.sleep(0)
+ t1 = loop.time()
+ self.assertTrue(cm.expired())
+ # 2 sec for slow CI boxes
+ self.assertLess(t1-t0, 2)
+ self.assertTrue(t0 >= cm.when() <= t1)
+
async def test_foreign_exception_passed(self):
with self.assertRaises(KeyError):
async with asyncio.timeout(0.01) as cm: