summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_time.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-22 23:15:27 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-22 23:15:27 (GMT)
commit6c86181cd1581f89d49fa0e1ccda20a0005d8283 (patch)
treecf2e5a079359cdad27cb828700147816b1b5c8f1 /Lib/test/test_time.py
parent0f57564cac8235961c9e64774dfb4069963c35de (diff)
downloadcpython-6c86181cd1581f89d49fa0e1ccda20a0005d8283.zip
cpython-6c86181cd1581f89d49fa0e1ccda20a0005d8283.tar.gz
cpython-6c86181cd1581f89d49fa0e1ccda20a0005d8283.tar.bz2
Issue #19715: Ensure that consecutive calls to monotonic() are monotonic
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r--Lib/test/test_time.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index faf9779..f3643b6 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -367,6 +367,14 @@ class TimeTestCase(unittest.TestCase):
@unittest.skipUnless(hasattr(time, 'monotonic'),
'need time.monotonic')
def test_monotonic(self):
+ # monotonic() should not go backward
+ times = [time.monotonic() for n in range(100)]
+ t1 = times[0]
+ for t2 in times[1:]:
+ self.assertGreaterEqual(t2, t1, "times=%s" % times)
+ t1 = t2
+
+ # monotonic() includes time elapsed during a sleep
t1 = time.monotonic()
time.sleep(0.5)
t2 = time.monotonic()
@@ -374,6 +382,7 @@ class TimeTestCase(unittest.TestCase):
self.assertGreater(t2, t1)
self.assertAlmostEqual(dt, 0.5, delta=0.2)
+ # monotonic() is a monotonic but non adjustable clock
info = time.get_clock_info('monotonic')
self.assertTrue(info.monotonic)
self.assertFalse(info.adjustable)