(
selenium_coverage: typing.Any, testserver_http: PyodideServerInfo
)
| 903 | |
| 904 | |
| 905 | def test_retries( |
| 906 | selenium_coverage: typing.Any, testserver_http: PyodideServerInfo |
| 907 | ) -> None: |
| 908 | @run_in_pyodide # type: ignore[untyped-decorator] |
| 909 | def pyodide_test(selenium_coverage, host: str, port: int) -> None: # type: ignore[no-untyped-def] |
| 910 | import pytest |
| 911 | |
| 912 | import urllib3 |
| 913 | |
| 914 | pool = urllib3.HTTPConnectionPool( |
| 915 | host, |
| 916 | port, |
| 917 | maxsize=1, |
| 918 | block=True, |
| 919 | retries=urllib3.util.Retry(connect=5, read=5, redirect=5), |
| 920 | ) |
| 921 | |
| 922 | # monkeypatch connection class to count calls |
| 923 | old_request = urllib3.connection.HTTPConnection.request |
| 924 | count = 0 |
| 925 | |
| 926 | def count_calls(self, *args, **argv): # type: ignore[no-untyped-def] |
| 927 | nonlocal count |
| 928 | count += 1 |
| 929 | return old_request(self, *args, **argv) |
| 930 | |
| 931 | urllib3.connection.HTTPConnection.request = count_calls # type: ignore[method-assign] |
| 932 | with pytest.raises(urllib3.exceptions.MaxRetryError): |
| 933 | pool.urlopen("GET", "/") |
| 934 | # this should fail, but should have tried 6 times total |
| 935 | assert count == 6 |
| 936 | |
| 937 | pyodide_test(selenium_coverage, testserver_http.http_host, find_unused_port()) |
| 938 | |
| 939 | |
| 940 | def test_redirects( |
nothing calls this directly
no test coverage detected