Skip to content

Commit

Permalink
replace try logic for test_autoscaling_config_fetch_retries
Browse files Browse the repository at this point in the history
Signed-off-by: wa101 <wadhah.mahroug15@gmail.com>
  • Loading branch information
wadhah101 committed Dec 2, 2024
1 parent 42a5326 commit f41cae2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions python/ray/tests/kuberay/test_autoscaling_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,19 @@ def test_autoscaling_config_fetch_retries(exception, num_exceptions):
AutoscalingConfigProducer._fetch_ray_cr_from_k8s_with_retries.
"""

class MockAutoscalingConfigProducer(AutoscalingConfigProducer):
def __init__(self, *args, **kwargs):
class MockKubernetesHttpApiClient:
def __init__(self):
self.exception_counter = 0

def _fetch_ray_cr_from_k8s(self) -> Dict[str, Any]:
if self.exception_counter < num_exceptions:
self.exception_counter += 1
raise exception
else:
return {"ok-key": "ok-value"}
def get(self, *args, **kwargs):
self.exception_counter += 1
if self.exception_counter <= num_exceptions:
raise requests.HTTPError("Mock HTTP Error")
return {"ok-key": "ok-value"}

class MockAutoscalingConfigProducer(AutoscalingConfigProducer):
def __init__(self, *args, **kwargs):
self.kubernetes_api_client = MockKubernetesHttpApiClient()

config_producer = MockAutoscalingConfigProducer()
# Patch retry backoff period.
Expand Down

0 comments on commit f41cae2

Please sign in to comment.