Skip to content

Commit

Permalink
Add integration test to verify non200 response handling (#1132)
Browse files Browse the repository at this point in the history
* add integ test to verify non200 response handling

* fix test

* run lint locally

* use different namespace to avoid collision

* try sending status back directly
  • Loading branch information
lennon310 authored and axsaucedo committed Nov 26, 2019
1 parent 77f751a commit 969e474
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
38 changes: 38 additions & 0 deletions testing/resources/s2i_python_model_non200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"apiVersion": "machinelearning.seldon.io/v1alpha2",
"kind": "SeldonDeployment",
"metadata": {
"name": "mymodel"
},
"spec": {
"name": "mymodel",
"oauth_key": "oauth-key",
"oauth_secret": "oauth-secret",
"predictors": [
{
"componentSpecs": [{
"spec": {
"containers": [
{
"image": "seldonio/testmodel_rest_non200:0.1",
"imagePullPolicy": "Never",
"name": "model"
}
],
"terminationGracePeriodSeconds": 1
}
}],
"graph": {
"children": [],
"name": "model",
"endpoint": {
"type" : "REST"
},
"type": "MODEL"
},
"name": "mymodel",
"replicas": 1
}
]
}
}
16 changes: 16 additions & 0 deletions testing/s2i/python/model/MyModelNon200Response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from flask.json import jsonify


class MyModelNon200Response(object):
def __init__(self, metrics_ok=True):
print("Init called")

def predict_raw(self, message):
status = {
"code": 400,
"reason": "exception message",
"status": "FAILURE",
"info": "exception caught",
}

return {"data": {"names": ["score"], "ndarray": []}, "status": status}
4 changes: 4 additions & 0 deletions testing/s2i/python/model/environment_rest_non200
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODEL_NAME=MyModelNon200Response
API_TYPE=REST
SERVICE_TYPE=MODEL
PERSISTENCE=0
28 changes: 28 additions & 0 deletions testing/scripts/test_s2i_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def test_model_rest(self, s2i_python_version):
tester = S2IK8S()
tester.test_model_rest(s2i_python_version)

def test_model_rest_non200(self, s2i_python_version):
tester = S2IK8S()
tester.test_model_rest_non200(s2i_python_version)

def test_input_transformer_rest(self, s2i_python_version):
tester = S2IK8S()
tester.test_input_transformer_rest(s2i_python_version)
Expand Down Expand Up @@ -153,6 +157,30 @@ def test_model_rest(self, s2i_python_version):
)
run(f"kubectl delete namespace {namespace}", shell=True)

def test_model_rest_non200(self, s2i_python_version):
namespace = "s2i-test-model-rest-non200"
retry_run(f"kubectl create namespace {namespace}")
create_push_s2i_image(s2i_python_version, "model", "rest_non200")
retry_run(
f"kubectl apply -f ../resources/s2i_python_model_non200.json -n {namespace}"
)
wait_for_rollout("mymodel-mymodel-4e3d66d", namespace)
r = initial_rest_request("mymodel", namespace)
arr = np.array([[1, 2, 3]])
r = rest_request_ambassador("mymodel", namespace, API_AMBASSADOR, data=arr)
res = r.json()
logging.warning(res)
assert r.status_code == 200
assert r.json()["status"]["code"] == 400
assert r.json()["status"]["reason"] == "exception message"
assert r.json()["status"]["info"] == "exception caught"
assert r.json()["status"]["status"] == "FAILURE"
run(
f"kubectl delete -f ../resources/s2i_python_model_non200.json -n {namespace}",
shell=True,
)
run(f"kubectl delete namespace {namespace}", shell=True)

def test_input_transformer_rest(self, s2i_python_version):
namespace = "s2i-test-input-transformer-rest"
retry_run(f"kubectl create namespace {namespace}")
Expand Down

0 comments on commit 969e474

Please sign in to comment.