from unittest.mock import patch from src.utils.awsretry import AWSRetry def test_awsretry_backoff_retries_and_succeeds(): calls = {"n": 0} @AWSRetry.backoff(tries=3, delay=0) def flaky(): calls["n"] += 1 if calls["n"] < 2: raise Exception("boom") return "ok" with patch("time.sleep"): assert flaky() == "ok" # One retry should have happened assert calls["n"] == 2 def test_awsretry_handles_exception_without_response(): calls = {"n": 0} @AWSRetry.backoff(tries=2, delay=0) def fail_once(): calls["n"] += 1 raise RuntimeError("no response attr") with patch("time.sleep"): with patch("src.utils.awsretry.logger"): try: fail_once() except RuntimeError: pass # Ensure retry attempted once assert calls["n"] == 2