8000 gh-90808: add more examples to `test_sched.test_priority` (GH-31144) · python/cpython@9a111a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a111a5

Browse files
gh-90808: add more examples to test_sched.test_priority (GH-31144)
(cherry picked from commit 57463d4) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent aced809 commit 9a111a5

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Lib/test/test_sched.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,23 @@ def test_priority(self):
9191
l = []
9292
fun = lambda x: l.append(x)
9393
scheduler = sched.scheduler(time.time, time.sleep)
94-
for priority in [1, 2, 3, 4, 5]:
95-
z = scheduler.enterabs(0.01, priority, fun, (priority,))
96-
scheduler.run()
97-
self.assertEqual(l, [1, 2, 3, 4, 5])
94+
95+
cases = [
96+
([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]),
97+
([5, 4, 3, 2, 1], [1, 2, 3, 4, 5]),
98+
([2, 5, 3, 1, 4], [1, 2, 3, 4, 5]),
99+
([1, 2, 3, 2, 1], [1, 1, 2, 2, 3]),
100+
]
101+
for priorities, expected in cases:
102+
with self.subTest(priorities=priorities, expected=expected):
103+
for priority in priorities:
104+
scheduler.enterabs(0.01, priority, fun, (priority,))
105+
scheduler.run()
106+
self.assertEqual(l, expected)
107+
108+
# Cleanup:
109+
self.assertTrue(scheduler.empty())
110+
l.clear()
98111

99112
def test_cancel(self):
100113
l = []

0 commit comments

Comments
 (0)
0