vinodkc commented on code in PR #57320:
URL: https://github.com/apache/spark/pull/57320#discussion_r3605553877
##########
python/pyspark/sql/tests/connect/client/test_client_retries.py:
##########
@@ -256,6 +270,104 @@ def
test_deadline_exceeded_not_retried_by_retry_handler(self):
self.assertEqual(tries, 1)
self.assertEqual(len(sleep_tracker.times), 0)
+ def test_retry_exception_bounded_by_elapsed_time(self):
+ # Each attempt simulates a full 10-min reattach deadline elapsing
before RetryException
+ # is raised. The elapsed clock starts on the first RetryException,
after that attempt
+ # already advanced the clock, so with a 1-hour bound and a
10-min-per-attempt advance the
+ # loop gives up after bound // increment + 1 = 7 attempts: attempts
1-6 leave elapsed
+ # < 1h, and attempt 7 leaves elapsed = 6 * 10min = 1h >= bound,
tripping the throw.
+ client = SparkConnectClient("sc://foo/;token=bar")
+ clock = FakeClock()
+ cause = TestException("deadline exceeded",
code=grpc.StatusCode.DEADLINE_EXCEEDED)
+ tries = 0
+ with self.assertRaises(TestException) as cm:
+ for attempt in Retrying(
+ client._retry_policies,
+ sleep=lambda t: None,
+ now=clock.now,
+
max_retry_exception_elapsed_time=DEFAULT_MAX_RETRY_EXCEPTION_ELAPSED_TIME,
+ ):
+ with attempt:
+ tries += 1
+ clock.advance(10 * 60)
+ raise RetryException() from cause
+ self.assertIs(cm.exception, cause)
+ self.assertEqual(tries, 7)
+
+ def test_retry_exception_below_bound_keeps_retrying(self):
+ # Non-regression: well under the elapsed-time budget, RetryException
retries should
+ # keep behaving as before (immediate retry, no policy consulted) until
success.
+ client = SparkConnectClient("sc://foo/;token=bar")
+ clock = FakeClock()
+ tries = 0
+ for attempt in Retrying(
+ client._retry_policies,
+ sleep=lambda t: None,
+ now=clock.now,
+
max_retry_exception_elapsed_time=DEFAULT_MAX_RETRY_EXCEPTION_ELAPSED_TIME,
+ ):
+ with attempt:
+ tries += 1
+ if tries <= 3:
+ clock.advance(10)
+ raise RetryException()
+ self.assertEqual(tries, 4)
+
+ def
test_retry_exception_bare_no_cause_raises_self_when_bound_exceeded(self):
+ # If a RetryException has no attached cause (e.g. the
OPERATION_NOT_FOUND/
+ # SESSION_NOT_FOUND path, which today raises a bare RetryException),
falling back to
+ # raising the bare RetryException itself once the bound is exceeded.
Review Comment:
Fixed.
Thanks
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]