summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sched.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-02-16 18:51:45 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-02-16 18:51:45 (GMT)
commit4a72ebe34b6b484a62a418ceb6b398881945fd3a (patch)
tree469a3c28b20978082087e40e578a651ae60e54ae /Lib/test/test_sched.py
parent292f9a891d214fd5098bedb9b4117fc9c36a0fe7 (diff)
parentf670ca5e70962cf7fbc5b1c5758fb70d9c2e0e00 (diff)
downloadcpython-4a72ebe34b6b484a62a418ceb6b398881945fd3a.zip
cpython-4a72ebe34b6b484a62a418ceb6b398881945fd3a.tar.gz
cpython-4a72ebe34b6b484a62a418ceb6b398881945fd3a.tar.bz2
Issue #13878: Fix random test_sched failures.
Diffstat (limited to 'Lib/test/test_sched.py')
-rw-r--r--Lib/test/test_sched.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py
index ae82f94..50ada52 100644
--- a/Lib/test/test_sched.py
+++ b/Lib/test/test_sched.py
@@ -12,10 +12,10 @@ class TestCase(unittest.TestCase):
l = []
fun = lambda x: l.append(x)
scheduler = sched.scheduler(time.time, time.sleep)
- for x in [0.05, 0.04, 0.03, 0.02, 0.01]:
+ for x in [0.5, 0.4, 0.3, 0.2, 0.1]:
z = scheduler.enter(x, 1, fun, (x,))
scheduler.run()
- self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05])
+ self.assertEqual(l, [0.1, 0.2, 0.3, 0.4, 0.5])
def test_enterabs(self):
l = []
@@ -31,7 +31,7 @@ class TestCase(unittest.TestCase):
fun = lambda x: l.append(x)
scheduler = sched.scheduler(time.time, time.sleep)
for priority in [1, 2, 3, 4, 5]:
- z = scheduler.enter(0.01, priority, fun, (priority,))
+ z = scheduler.enterabs(0.01, priority, fun, (priority,))
scheduler.run()
self.assertEqual(l, [1, 2, 3, 4, 5])
@@ -39,11 +39,12 @@ class TestCase(unittest.TestCase):
l = []
fun = lambda x: l.append(x)
scheduler = sched.scheduler(time.time, time.sleep)
- event1 = scheduler.enter(0.01, 1, fun, (0.01,))
- event2 = scheduler.enter(0.02, 1, fun, (0.02,))
- event3 = scheduler.enter(0.03, 1, fun, (0.03,))
- event4 = scheduler.enter(0.04, 1, fun, (0.04,))
- event5 = scheduler.enter(0.05, 1, fun, (0.05,))
+ now = time.time()
+ event1 = scheduler.enterabs(now + 0.01, 1, fun, (0.01,))
+ event2 = scheduler.enterabs(now + 0.02, 1, fun, (0.02,))
+ event3 = scheduler.enterabs(now + 0.03, 1, fun, (0.03,))
+ event4 = scheduler.enterabs(now + 0.04, 1, fun, (0.04,))
+ event5 = scheduler.enterabs(now + 0.05, 1, fun, (0.05,))
scheduler.cancel(event1)
scheduler.cancel(event5)
scheduler.run()
@@ -64,11 +65,12 @@ class TestCase(unittest.TestCase):
l = []
fun = lambda x: l.append(x)
scheduler = sched.scheduler(time.time, time.sleep)
- e5 = scheduler.enter(0.05, 1, fun)
- e1 = scheduler.enter(0.01, 1, fun)
- e2 = scheduler.enter(0.02, 1, fun)
- e4 = scheduler.enter(0.04, 1, fun)
- e3 = scheduler.enter(0.03, 1, fun)
+ now = time.time()
+ e5 = scheduler.enterabs(now + 0.05, 1, fun)
+ e1 = scheduler.enterabs(now + 0.01, 1, fun)
+ e2 = scheduler.enterabs(now + 0.02, 1, fun)
+ e4 = scheduler.enterabs(now + 0.04, 1, fun)
+ e3 = scheduler.enterabs(now + 0.03, 1, fun)
# queue property is supposed to return an order list of
# upcoming events
self.assertEqual(list(scheduler.queue), [e1, e2, e3, e4, e5])