]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-90808: add more examples to `test_sched.test_priority` (GH-31144)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 21 Sep 2022 02:03:13 +0000 (19:03 -0700)
committerGitHub <noreply@github.com>
Wed, 21 Sep 2022 02:03:13 +0000 (19:03 -0700)
(cherry picked from commit 57463d43dc4277a1f4d33bd003567e947c937cf5)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_sched.py

index 32cc8105bc0557d4f7dcbc8bf37a5e32997edf42..eb52ac7983f6c8e705640af65693d6c2600d9f54 100644 (file)
@@ -92,10 +92,23 @@ class TestCase(unittest.TestCase):
         l = []
         fun = lambda x: l.append(x)
         scheduler = sched.scheduler(time.time, time.sleep)
-        for priority in [1, 2, 3, 4, 5]:
-            z = scheduler.enterabs(0.01, priority, fun, (priority,))
-        scheduler.run()
-        self.assertEqual(l, [1, 2, 3, 4, 5])
+
+        cases = [
+            ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]),
+            ([5, 4, 3, 2, 1], [1, 2, 3, 4, 5]),
+            ([2, 5, 3, 1, 4], [1, 2, 3, 4, 5]),
+            ([1, 2, 3, 2, 1], [1, 1, 2, 2, 3]),
+        ]
+        for priorities, expected in cases:
+            with self.subTest(priorities=priorities, expected=expected):
+                for priority in priorities:
+                    scheduler.enterabs(0.01, priority, fun, (priority,))
+                scheduler.run()
+                self.assertEqual(l, expected)
+
+                # Cleanup:
+                self.assertTrue(scheduler.empty())
+                l.clear()
 
     def test_cancel(self):
         l = []