Skip to content

Commit 6ba7465

Browse files
committed
Add test_fast_path_avoid_busy_loop
1 parent 6d8e36c commit 6ba7465

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Lib/test/test_subprocess.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,6 +4201,20 @@ def test_pidfd_open_notification_without_immediate_reap(self):
42014201
def test_kqueue_notification_without_immediate_reap(self):
42024202
self.assert_notification_without_immediate_reap("_wait_kqueue")
42034203

4204+
@unittest.skipUnless(
4205+
CAN_USE_PIDFD_OPEN or CAN_USE_KQUEUE,
4206+
"fast wait mechanism not available"
4207+
)
4208+
def test_fast_path_avoid_busy_loop(self):
4209+
# assert that the busy loop is not called as long as the fast
4210+
# wait is available
4211+
with mock.patch('time.sleep') as m:
4212+
p = subprocess.Popen([sys.executable,
4213+
"-c", "import time; time.sleep(0.3)"])
4214+
with self.assertRaises(subprocess.TimeoutExpired):
4215+
p.wait(timeout=0.0001)
4216+
self.assertEqual(p.wait(timeout=support.LONG_TIMEOUT), 0)
4217+
assert not m.called
42044218

42054219
if __name__ == "__main__":
42064220
unittest.main()

0 commit comments

Comments
 (0)