Skip to content

Commit 1e70937

Browse files
committed
feat: add replicas test
1 parent 130b812 commit 1e70937

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

tests/model_serving/model_server/inference_service_configuration/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ def patched_isvc_replicas(
5757
}
5858
}
5959
},
60+
wait_for_new_pods=request.param["wait-for-new-pods"],
6061
):
6162
yield ovms_kserve_inference_service

tests/model_serving/model_server/inference_service_configuration/test_isvc_replicas_update.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import pytest
2+
from simple_logger.logger import get_logger
3+
from timeout_sampler import TimeoutSampler
24

35
from tests.model_serving.model_server.inference_service_configuration.constants import (
46
BASE_ISVC_CONFIG,
57
RUNTIME_CONFIG,
68
)
7-
from tests.model_serving.model_server.inference_service_configuration.utils import (
8-
wait_for_new_running_inference_pods,
9-
)
109
from tests.model_serving.model_server.utils import verify_inference_response
1110
from utilities.constants import (
1211
KServeDeploymentType,
1312
Protocols,
13+
Timeout,
1414
)
1515
from utilities.inference_utils import Inference
16+
from utilities.infra import get_pods_by_isvc_label
1617
from utilities.manifests.onnx import ONNX_INFERENCE_CONFIG
1718

19+
20+
LOGGER = get_logger(name=__name__)
21+
1822
pytestmark = [pytest.mark.sanity, pytest.mark.usefixtures("valid_aws_config")]
1923

2024

@@ -37,9 +41,9 @@
3741
)
3842
class TestRawISVCReplicasUpdates:
3943
@pytest.mark.dependency(name="test_raw_increase_isvc_replicas")
40-
def test_raw_increase_isvc_replicas(self, isvc_pods, patched_isvc_replicas):
44+
def test_raw_increase_isvc_replicas(self, isvc_pods, ovms_kserve_inference_service):
4145
"""Test replicas increase"""
42-
wait_for_new_running_inference_pods(isvc=patched_isvc_replicas, orig_pods=isvc_pods, expected_num_pods=2)
46+
assert len(isvc_pods) == 2, "Expected 2 inference pods, existing pods: {pod.name for pod in isvc_pods}"
4347

4448
@pytest.mark.dependency(depends=["test_raw_increase_isvc_replicas"])
4549
def test_raw_increase_isvc_replicas_inference(self, ovms_kserve_inference_service):
@@ -55,14 +59,29 @@ def test_raw_increase_isvc_replicas_inference(self, ovms_kserve_inference_servic
5559
@pytest.mark.parametrize(
5660
"patched_isvc_replicas",
5761
[
58-
pytest.param({"min-replicas": 1, "max-replicas": 1}),
62+
pytest.param({"min-replicas": 1, "max-replicas": 1, "wait-for-new-pods": False}),
5963
],
6064
indirect=True,
6165
)
6266
@pytest.mark.dependency(name="test_raw_decrease_isvc_replicas")
63-
def test_raw_decrease_isvc_replicas(self, isvc_pods, patched_isvc_replicas):
67+
def test_raw_decrease_isvc_replicas(self, admin_client, isvc_pods, patched_isvc_replicas):
6468
"""Test replicas decrease"""
65-
wait_for_new_running_inference_pods(isvc=patched_isvc_replicas, orig_pods=isvc_pods, expected_num_pods=2)
69+
orig_pod_names = [pod.name for pod in isvc_pods]
70+
pods = []
71+
72+
try:
73+
for pods in TimeoutSampler(
74+
wait_timeout=Timeout.TIMEOUT_2MIN,
75+
sleep=1,
76+
func=get_pods_by_isvc_label,
77+
client=admin_client,
78+
isvc=patched_isvc_replicas,
79+
):
80+
if len(pods) == 1 and pods[0].name in orig_pod_names:
81+
return
82+
83+
except TimeoutError:
84+
LOGGER.error(f"Expected 1 pod to be running, but got {[_pod.name for _pod in pods]}")
6685

6786
@pytest.mark.dependency(depends=["test_raw_decrease_isvc_replicas"])
6887
def test_raw_decrease_isvc_replicas_inference(self, ovms_kserve_inference_service):

tests/model_serving/model_server/inference_service_configuration/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
@contextmanager
2020
def update_inference_service(
21-
client: DynamicClient, isvc: InferenceService, isvc_updated_dict: dict[str, Any]
21+
client: DynamicClient, isvc: InferenceService, isvc_updated_dict: dict[str, Any], wait_for_new_pods: bool = True
2222
) -> Generator[InferenceService, Any, None]:
2323
"""
2424
Update InferenceService object.
@@ -27,12 +27,14 @@ def update_inference_service(
2727
client (DynamicClient): DynamicClient object.
2828
isvc (InferenceService): InferenceService object.
2929
isvc_updated_dict (dict[str, Any]): InferenceService object.
30+
wait_for_new_pods (bool): Whether to wait for new pods to be created.
3031
3132
"""
3233
orig_pods = get_pods_by_isvc_label(client=client, isvc=isvc)
3334

3435
with ResourceEditor(patches={isvc: isvc_updated_dict}):
35-
wait_for_new_running_inference_pods(isvc=isvc, orig_pods=orig_pods)
36+
if wait_for_new_pods:
37+
wait_for_new_running_inference_pods(isvc=isvc, orig_pods=orig_pods)
3638

3739
yield isvc
3840

0 commit comments

Comments
 (0)