24
24
25
25
from multi_model_endpoint_test_utils import make_load_model_request , make_headers
26
26
27
-
28
27
PING_URL = "http://localhost:8080/ping"
29
28
INVOCATION_URL = "http://localhost:8080/models/{}/invoke"
30
- MODEL_NAME = "half_plus_three"
29
+ MODEL_NAME_1 = "half_plus_three"
30
+ MODEL_NAME_2 = "half_plus_two"
31
31
32
32
33
33
@pytest .fixture (scope = "session" , autouse = True )
@@ -74,13 +74,22 @@ def container(docker_base_name, tag, runtime_config):
74
74
75
75
76
76
@pytest .fixture
77
- def model ():
77
+ def model1 ():
78
78
model_data = {
79
- "model_name" : MODEL_NAME ,
79
+ "model_name" : MODEL_NAME_1 ,
80
80
"url" : "/opt/ml/models/half_plus_three/model/half_plus_three"
81
81
}
82
82
make_load_model_request (json .dumps (model_data ))
83
- return MODEL_NAME
83
+ return MODEL_NAME_1
84
+
85
+ @pytest .fixture
86
+ def model2 ():
87
+ model_data = {
88
+ "model_name" : MODEL_NAME_2 ,
89
+ "url" : "/opt/ml/models/half_plus_two/model/half_plus_two"
90
+ }
91
+ make_load_model_request (json .dumps (model_data ))
92
+ return MODEL_NAME_2
84
93
85
94
86
95
@pytest .mark .skip_gpu
@@ -90,20 +99,33 @@ def test_ping_service():
90
99
91
100
92
101
@pytest .mark .skip_gpu
93
- def test_predict_json (model ):
102
+ def test_predict_json (model1 , model2 ):
94
103
headers = make_headers ()
95
104
data = "{\" instances\" : [1.0, 2.0, 5.0]}"
96
- response = requests .post (INVOCATION_URL .format (model ), data = data , headers = headers ).json ()
97
- assert response == {"predictions" : [3.5 , 4.0 , 5.5 ]}
105
+ response1 = requests .post (INVOCATION_URL .format (model1 ), data = data , headers = headers ).json ()
106
+ assert response1 == {"predictions" : [3.5 , 4.0 , 5.5 ]}
107
+ response2 = requests .post (INVOCATION_URL .format (model2 ), data = data , headers = headers ).json ()
108
+ assert response2 == {"predictions" : [2.5 , 3.0 , 4.5 ]}
98
109
99
110
100
111
@pytest .mark .skip_gpu
101
112
def test_zero_content ():
102
113
headers = make_headers ()
103
114
x = ""
104
- response = requests .post (INVOCATION_URL .format (MODEL_NAME ), data = x , headers = headers )
105
- assert 500 == response .status_code
106
- assert "document is empty" in response .text
115
+ response1 = requests .post (INVOCATION_URL .format (MODEL_NAME_1 ), data = x , headers = headers )
116
+ print ("Response 1 status code:" )
117
+ print (response1 .status_code )
118
+ print ("Response 1 text:" )
119
+ print (response1 .text )
120
+ assert 500 == response1 .status_code
121
+ assert "document is empty" in response1 .text
122
+ response2 = requests .post (INVOCATION_URL .format (MODEL_NAME_2 ), data = x , headers = headers )
123
+ print ("Response 2 status code:" )
124
+ print (response2 .status_code )
125
+ print ("Response 2 text:" )
126
+ print (response2 .text )
127
+ assert 500 == response2 .status_code
128
+ assert "document is empty" in response2 .text
107
129
108
130
109
131
@pytest .mark .skip_gpu
@@ -113,34 +135,66 @@ def test_large_input():
113
135
with open (data_file , "r" ) as file :
114
136
x = file .read ()
115
137
headers = make_headers (content_type = "text/csv" )
116
- response = requests .post (INVOCATION_URL .format (MODEL_NAME ), data = x , headers = headers ).json ()
117
- predictions = response ["predictions" ]
118
- assert len (predictions ) == 753936
138
+ response1 = requests .post (INVOCATION_URL .format (MODEL_NAME_1 ), data = x , headers = headers ).json ()
139
+ predictions1 = response1 ["predictions" ]
140
+ print ("Response 1:" )
141
+ print (response1 )
142
+ assert len (predictions1 ) == 753936
143
+ response2 = requests .post (INVOCATION_URL .format (MODEL_NAME_2 ), data = x , headers = headers ).json ()
144
+ print ("Response 2:" )
145
+ print (response2 )
146
+ predictions2 = response2 ["predictions" ]
147
+ assert len (predictions2 ) == 753936
119
148
120
149
121
150
@pytest .mark .skip_gpu
122
151
def test_csv_input ():
123
152
headers = make_headers (content_type = "text/csv" )
124
153
data = "1.0,2.0,5.0"
125
- response = requests .post (INVOCATION_URL .format (MODEL_NAME ), data = data , headers = headers ).json ()
126
- assert response == {"predictions" : [3.5 , 4.0 , 5.5 ]}
154
+ response1 = requests .post (INVOCATION_URL .format (MODEL_NAME_1 ), data = data , headers = headers ).json ()
155
+ print ("Response 1:" )
156
+ print (response1 )
157
+ assert response1 == {"predictions" : [3.5 , 4.0 , 5.5 ]}
158
+ response2 = requests .post (INVOCATION_URL .format (MODEL_NAME_2 ), data = data , headers = headers ).json ()
159
+ print ("Response 2:" )
160
+ print (response2 )
161
+ assert response2 == {"predictions" : [2.5 , 3.0 , 4.5 ]}
127
162
128
163
129
164
@pytest .mark .skip_gpu
130
165
def test_specific_versions ():
131
166
for version in ("123" , "124" ):
132
167
headers = make_headers (content_type = "text/csv" , version = version )
133
168
data = "1.0,2.0,5.0"
134
- response = requests .post (
135
- INVOCATION_URL .format (MODEL_NAME ), data = data , headers = headers
169
+ response1 = requests .post (
170
+ INVOCATION_URL .format (MODEL_NAME_1 ), data = data , headers = headers
171
+ ).json ()
172
+ print ("Response 1" )
173
+ print (response1 )
174
+ assert response1 == {"predictions" : [3.5 , 4.0 , 5.5 ]}
175
+ response2 = requests .post (
176
+ INVOCATION_URL .format (MODEL_NAME_2 ), data = data , headers = headers
136
177
).json ()
137
- assert response == {"predictions" : [3.5 , 4.0 , 5.5 ]}
178
+ print ("Response 2:" )
179
+ print (response2 )
180
+ assert response2 == {"predictions" : [2.5 , 3.0 , 4.5 ]}
138
181
139
182
140
183
@pytest .mark .skip_gpu
141
184
def test_unsupported_content_type ():
142
185
headers = make_headers ("unsupported-type" , "predict" )
143
186
data = "aW1hZ2UgYnl0ZXM="
144
- response = requests .post (INVOCATION_URL .format (MODEL_NAME ), data = data , headers = headers )
145
- assert 500 == response .status_code
146
- assert "unsupported content type" in response .text
187
+ response1 = requests .post (INVOCATION_URL .format (MODEL_NAME_1 ), data = data , headers = headers )
188
+ print ("Response 1 status code:" )
189
+ print (response1 .status_code )
190
+ print ("Response 1 text:" )
191
+ print (response1 .text )
192
+ assert 500 == response1 .status_code
193
+ assert "unsupported content type" in response1 .text
194
+ response2 = requests .post (INVOCATION_URL .format (MODEL_NAME_2 ), data = data , headers = headers )
195
+ print ("Response 2 status code:" )
196
+ print (response2 .status_code )
197
+ print ("Response 2 text:" )
198
+ print (response2 .text )
199
+ assert 500 == response2 .status_code
200
+ assert "unsupported content type" in response2 .text
0 commit comments