From 6c86181cd1581f89d49fa0e1ccda20a0005d8283 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 23 Nov 2013 00:15:27 +0100 Subject: [PATCH] Issue #19715: Ensure that consecutive calls to monotonic() are monotonic --- Lib/test/test_time.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index faf9779a47..f3643b63ff 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) -- 2.40.0