|
1 | 1 | import io |
| 2 | +import time |
2 | 3 | import json |
3 | 4 | import os |
4 | 5 | import signal |
@@ -462,8 +463,6 @@ def test_breakpoints(self): |
462 | 463 | self.assertIn("Function returned: 42", stdout) |
463 | 464 | self.assertEqual(process.returncode, 0) |
464 | 465 |
|
465 | | - # gh-132912: The test fails randomly |
466 | | - @unittest.skipIf(True, "flaky test") |
467 | 466 | def test_keyboard_interrupt(self): |
468 | 467 | """Test that sending keyboard interrupt breaks into pdb.""" |
469 | 468 | synchronizer_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
@@ -512,15 +511,22 @@ def bar(): |
512 | 511 | # Wait until execution has continued |
513 | 512 | synchronizer_sock.accept()[0].close() |
514 | 513 |
|
| 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 | + |
515 | 519 | # Inject a script to interrupt the running process |
516 | 520 | self._send_interrupt(process.pid) |
517 | 521 | messages = self._read_until_prompt(client_file) |
518 | 522 |
|
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) |
522 | 528 |
|
523 | | - # Continue to end |
| 529 | + # Continue to end as fast as we can |
524 | 530 | self._send_command(client_file, "iterations = 0") |
525 | 531 | self._send_command(client_file, "c") |
526 | 532 | stdout, _ = process.communicate(timeout=5) |
|
0 commit comments