Skip to content

Commit 6cbeb6a

Browse files
authored
gh-132912: Account for race in test_keyboard_interrupt in test_remote_pdb (#132929)
1 parent 52454c5 commit 6cbeb6a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Lib/test/test_remote_pdb.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import time
23
import json
34
import os
45
import signal
@@ -462,8 +463,6 @@ def test_breakpoints(self):
462463
self.assertIn("Function returned: 42", stdout)
463464
self.assertEqual(process.returncode, 0)
464465

465-
# gh-132912: The test fails randomly
466-
@unittest.skipIf(True, "flaky test")
467466
def test_keyboard_interrupt(self):
468467
"""Test that sending keyboard interrupt breaks into pdb."""
469468
synchronizer_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -512,15 +511,22 @@ def bar():
512511
# Wait until execution has continued
513512
synchronizer_sock.accept()[0].close()
514513

514+
# Wait a bit so the remote leaves create_connection(). This is not
515+
# required but makes the rest of the test faster as we will exit the main
516+
# loop immediately by setting iterations to 0.
517+
time.sleep(0.1)
518+
515519
# Inject a script to interrupt the running process
516520
self._send_interrupt(process.pid)
517521
messages = self._read_until_prompt(client_file)
518522

519-
# Verify we got the keyboard interrupt message
520-
interrupt_msg = next(msg['message'] for msg in messages if 'message' in msg)
521-
self.assertIn("bar()", interrupt_msg)
523+
# Verify we got the keyboard interrupt message. Is possible that we get interrupted somewhere
524+
# in bar() or when leving create_connection()
525+
interrupt_msgs = [msg['message'] for msg in messages if 'message' in msg]
526+
expected_msg = [msg for msg in interrupt_msgs if "bar()" in msg or "create_connection()" in msg]
527+
self.assertGreater(len(expected_msg), 0)
522528

523-
# Continue to end
529+
# Continue to end as fast as we can
524530
self._send_command(client_file, "iterations = 0")
525531
self._send_command(client_file, "c")
526532
stdout, _ = process.communicate(timeout=5)

0 commit comments

Comments
 (0)