|
| 1 | +import logging |
| 2 | + |
| 3 | +import pytest |
| 4 | +import requests.exceptions |
| 5 | +from re_assert import Matches |
| 6 | + |
| 7 | +from openeo.rest.http import requests_with_retry |
| 8 | + |
| 9 | + |
| 10 | +def test_requests_with_retry(caplog): |
| 11 | + """Simple test for retrying using an invalid domain.""" |
| 12 | + caplog.set_level(logging.DEBUG) |
| 13 | + |
| 14 | + session = requests_with_retry(total=2, backoff_factor=0.1) |
| 15 | + with pytest.raises(requests.exceptions.ConnectionError, match="Max retries exceeded"): |
| 16 | + _ = session.get("https://example.test") |
| 17 | + |
| 18 | + assert caplog.messages == [ |
| 19 | + "Starting new HTTPS connection (1): example.test:443", |
| 20 | + Matches("Incremented Retry.*Retry\(total=1"), |
| 21 | + # Matches("Retrying.*total=1.*Failed to establish a new connection"), |
| 22 | + Matches("Retrying.*total=1.*Failed to resolve 'example.test'"), |
| 23 | + "Starting new HTTPS connection (2): example.test:443", |
| 24 | + Matches("Incremented Retry.*Retry\(total=0"), |
| 25 | + Matches("Retrying.*total=0.*Failed to resolve 'example.test'"), |
| 26 | + "Starting new HTTPS connection (3): example.test:443", |
| 27 | + ] |
| 28 | + |
| 29 | + |
| 30 | +def test_requests_with_retry_zero(caplog): |
| 31 | + """Simple test for retrying using an invalid domain.""" |
| 32 | + caplog.set_level(logging.DEBUG) |
| 33 | + |
| 34 | + session = requests_with_retry(total=0) |
| 35 | + with pytest.raises(requests.exceptions.ConnectionError, match="Max retries exceeded"): |
| 36 | + _ = session.get("https://example.test") |
| 37 | + |
| 38 | + assert caplog.messages == [ |
| 39 | + "Starting new HTTPS connection (1): example.test:443", |
| 40 | + ] |
0 commit comments