diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-12-17 08:36:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-17 08:36:36 (GMT) |
commit | 2cf4c202ffeb30787c944365ba54013688b854c2 (patch) | |
tree | aa98e69de819cb1cd0f5bd25fb10636f98001ff2 /Lib/test/_test_multiprocessing.py | |
parent | 4e80f5cbeaee87a26e49bc9623c92a10e28dbbd9 (diff) | |
download | cpython-2cf4c202ffeb30787c944365ba54013688b854c2.zip cpython-2cf4c202ffeb30787c944365ba54013688b854c2.tar.gz cpython-2cf4c202ffeb30787c944365ba54013688b854c2.tar.bz2 |
bpo-35513: Replace time.time() with time.monotonic() in tests (GH-11182)
Replace time.time() with time.monotonic() in tests to measure time
delta.
test_zipfile64: display progress every minute (60 secs) rather than
every 5 minutes (5*60 seconds).
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index a2dc53c..b5597d5 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -155,11 +155,11 @@ class TimingWrapper(object): self.elapsed = None def __call__(self, *args, **kwds): - t = time.time() + t = time.monotonic() try: return self.func(*args, **kwds) finally: - self.elapsed = time.time() - t + self.elapsed = time.monotonic() - t # # Base class for test cases @@ -1034,9 +1034,9 @@ class _TestQueue(BaseTestCase): def test_timeout(self): q = multiprocessing.Queue() - start = time.time() + start = time.monotonic() self.assertRaises(pyqueue.Empty, q.get, True, 0.200) - delta = time.time() - start + delta = time.monotonic() - start # bpo-30317: Tolerate a delta of 100 ms because of the bad clock # resolution on Windows (usually 15.6 ms). x86 Windows7 3.x once # failed because the delta was only 135.8 ms. @@ -1440,9 +1440,9 @@ class _TestCondition(BaseTestCase): sem.release() with cond: expected = 0.1 - dt = time.time() + dt = time.monotonic() result = cond.wait_for(lambda : state.value==4, timeout=expected) - dt = time.time() - dt + dt = time.monotonic() - dt # borrow logic in assertTimeout() from test/lock_tests.py if not result and expected * 0.6 < dt < expected * 10.0: success.value = True @@ -2533,7 +2533,7 @@ class _TestPool(BaseTestCase): # process would fill the result queue (after the result handler thread # terminated, hence not draining it anymore). - t_start = time.time() + t_start = time.monotonic() with self.assertRaises(ValueError): with self.Pool(2) as p: @@ -2545,7 +2545,7 @@ class _TestPool(BaseTestCase): p.join() # check that we indeed waited for all jobs - self.assertGreater(time.time() - t_start, 0.9) + self.assertGreater(time.monotonic() - t_start, 0.9) def test_release_task_refs(self): # Issue #29861: task arguments and results should not be kept @@ -4108,9 +4108,9 @@ class TestWait(unittest.TestCase): expected = 5 a, b = multiprocessing.Pipe() - start = time.time() + start = time.monotonic() res = wait([a, b], expected) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(res, []) self.assertLess(delta, expected * 2) @@ -4118,9 +4118,9 @@ class TestWait(unittest.TestCase): b.send(None) - start = time.time() + start = time.monotonic() res = wait([a, b], 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(res, [a]) self.assertLess(delta, 0.4) @@ -4144,9 +4144,9 @@ class TestWait(unittest.TestCase): self.assertIsInstance(p.sentinel, int) self.assertTrue(sem.acquire(timeout=20)) - start = time.time() + start = time.monotonic() res = wait([a, p.sentinel, b], expected + 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(res, [p.sentinel]) self.assertLess(delta, expected + 2) @@ -4154,18 +4154,18 @@ class TestWait(unittest.TestCase): a.send(None) - start = time.time() + start = time.monotonic() res = wait([a, p.sentinel, b], 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(sorted_(res), sorted_([p.sentinel, b])) self.assertLess(delta, 0.4) b.send(None) - start = time.time() + start = time.monotonic() res = wait([a, p.sentinel, b], 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(sorted_(res), sorted_([a, p.sentinel, b])) self.assertLess(delta, 0.4) @@ -4176,9 +4176,9 @@ class TestWait(unittest.TestCase): def test_neg_timeout(self): from multiprocessing.connection import wait a, b = multiprocessing.Pipe() - t = time.time() + t = time.monotonic() res = wait([a], timeout=-1) - t = time.time() - t + t = time.monotonic() - t self.assertEqual(res, []) self.assertLess(t, 1) a.close() |