Commit e11b531
fix: rewrite stale-keepalive retry test without real socket dependence
The original integration-style test spun up a real uvicorn server with
timeout_keep_alive=0, established a connection, slept 100 ms to give
the server time to close the socket, monkeypatched urllib3's
is_connected property to lie once, then asserted the resulting
ConnectionError caused HTTPClient to retry.
The assertion was flaky on Linux + Python 3.14 + latest deps, where
either the FIN didn't arrive in 100 ms reliably or newer urllib3
transparently refreshed the stale connection — in both cases the first
request succeeded without raising, so HTTPClient's retry never fired
and mock.call_count came in at 1 instead of 2.
That brittleness is testing real-socket timing and urllib3 internals,
not HTTPClient's contract. The contract is just: "if session.request
raises ConnectionError, retry once". Inject the ConnectionError at the
session layer directly — same assertion, no environment dependence.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 25b6a33 commit e11b531
1 file changed
Lines changed: 23 additions & 65 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
626 | | - | |
627 | | - | |
| 626 | + | |
| 627 | + | |
628 | 628 | | |
629 | | - | |
630 | | - | |
631 | | - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
632 | 633 | | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
| 634 | + | |
654 | 635 | | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
667 | 641 | | |
668 | | - | |
669 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
670 | 648 | | |
671 | | - | |
672 | | - | |
| 649 | + | |
673 | 650 | | |
674 | | - | |
675 | | - | |
676 | | - | |
| 651 | + | |
677 | 652 | | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
| 653 | + | |
| 654 | + | |
697 | 655 | | |
698 | 656 | | |
699 | 657 | | |
| |||
0 commit comments