summaryrefslogtreecommitdiffstats
path: root/Lib/test/lock_tests.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-12-17 08:36:36 (GMT)
committerGitHub <noreply@github.com>2018-12-17 08:36:36 (GMT)
commit2cf4c202ffeb30787c944365ba54013688b854c2 (patch)
treeaa98e69de819cb1cd0f5bd25fb10636f98001ff2 /Lib/test/lock_tests.py
parent4e80f5cbeaee87a26e49bc9623c92a10e28dbbd9 (diff)
downloadcpython-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/lock_tests.py')
-rw-r--r--Lib/test/lock_tests.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 65fa4d8..23a02e0 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -74,7 +74,7 @@ class BaseTestCase(unittest.TestCase):
support.reap_children()
def assertTimeout(self, actual, expected):
- # The waiting and/or time.time() can be imprecise, which
+ # The waiting and/or time.monotonic() can be imprecise, which
# is why comparing to the expected value would sometimes fail
# (especially under Windows).
self.assertGreaterEqual(actual, expected * 0.6)
@@ -190,16 +190,16 @@ class BaseLockTests(BaseTestCase):
# TIMEOUT_MAX is ok
lock.acquire(timeout=TIMEOUT_MAX)
lock.release()
- t1 = time.time()
+ t1 = time.monotonic()
self.assertTrue(lock.acquire(timeout=5))
- t2 = time.time()
+ t2 = time.monotonic()
# Just a sanity test that it didn't actually wait for the timeout.
self.assertLess(t2 - t1, 5)
results = []
def f():
- t1 = time.time()
+ t1 = time.monotonic()
results.append(lock.acquire(timeout=0.5))
- t2 = time.time()
+ t2 = time.monotonic()
results.append(t2 - t1)
Bunch(f, 1).wait_for_finished()
self.assertFalse(results[0])
@@ -382,9 +382,9 @@ class EventTests(BaseTestCase):
N = 5
def f():
results1.append(evt.wait(0.0))
- t1 = time.time()
+ t1 = time.monotonic()
r = evt.wait(0.5)
- t2 = time.time()
+ t2 = time.monotonic()
results2.append((r, t2 - t1))
Bunch(f, N).wait_for_finished()
self.assertEqual(results1, [False] * N)
@@ -545,9 +545,9 @@ class ConditionTests(BaseTestCase):
N = 5
def f():
cond.acquire()
- t1 = time.time()
+ t1 = time.monotonic()
result = cond.wait(0.5)
- t2 = time.time()
+ t2 = time.monotonic()
cond.release()
results.append((t2 - t1, result))
Bunch(f, N).wait_for_finished()
@@ -584,9 +584,9 @@ class ConditionTests(BaseTestCase):
success = []
def f():
with cond:
- dt = time.time()
+ dt = time.monotonic()
result = cond.wait_for(lambda : state==4, timeout=0.1)
- dt = time.time() - dt
+ dt = time.monotonic() - dt
self.assertFalse(result)
self.assertTimeout(dt, 0.1)
success.append(None)
@@ -692,9 +692,9 @@ class BaseSemaphoreTests(BaseTestCase):
self.assertFalse(sem.acquire(timeout=0.005))
sem.release()
self.assertTrue(sem.acquire(timeout=0.005))
- t = time.time()
+ t = time.monotonic()
self.assertFalse(sem.acquire(timeout=0.5))
- dt = time.time() - t
+ dt = time.monotonic() - t
self.assertTimeout(dt, 0.5)
def test_default_value(self):