uranusjr commented on code in PR #76571:
URL: https://github.com/apache/airflow/pull/76571#discussion_r4534225914


##########
task-sdk/tests/task_sdk/api/test_client.py:
##########
@@ -2608,6 +2616,30 @@ def handle_request(request: httpx2.Request) -> 
httpx2.Response:
 
 
 class TestCallbackOperations:
+    TOKEN_ALREADY_USED = "Callback token already used, possibly by an earlier 
attempt of this exchange"
+
+    @pytest.fixture
+    def clock(self):
+        """Make tenacity wait the minimum between attempts, on a clock that 
only its sleeps move."""
+
+        class Clock:
+            def __init__(self):
+                self.sleeps: list[float] = []
+
+            def monotonic(self) -> float:
+                return sum(self.sleeps)
+
+            def sleep(self, seconds: float) -> None:
+                self.sleeps.append(seconds)
+
+        clock = Clock()
+        with (
+            mock.patch("tenacity.time", clock),
+            mock.patch("tenacity.nap.time", clock),
+            mock.patch("tenacity.wait.random", SimpleNamespace(uniform=lambda 
low, high: low)),
+        ):
+            yield clock

Review Comment:
   These patches on tenacity internals could be brittle. We can probably do 
something like this instead
   
   ```python
   # client.py
   def _callback_run_stop() -> stop_base:
       """Make at least the usual number of attempts, and keep going while the 
server is down."""
       return stop_after_attempt(API_RETRIES) & 
stop_after_delay(API_RETRY_WAIT_MAX)
   
   # in run()
   retrying = Retrying(..., stop=_callback_run_stop(), ...)
   ```
   
   and just test against `_callback_run_stop`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to