Skip to content

Commit d2a284f

Browse files
authored
Add testing for new error handling API (#5892)
1 parent c14eb34 commit d2a284f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

qa/L0_backend_python/lifecycle/lifecycle_test.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ def setUp(self):
5858
self._shm_leak_detector = shm_util.ShmLeakDetector()
5959

6060
def test_batch_error(self):
61-
# The execute_error model returns an error for the first request and
62-
# sucessfully processes the second request. This is making sure that
63-
# an error in a single request does not completely fail the batch.
61+
# The execute_error model returns an error for the first and third
62+
# request and sucessfully processes the second request. This is making
63+
# sure that an error in a single request does not completely fail the
64+
# batch.
6465
model_name = "execute_error"
6566
shape = [2, 2]
66-
number_of_requests = 2
67+
number_of_requests = 3
6768
user_data = UserData()
6869
triton_client = grpcclient.InferenceServerClient("localhost:8001")
6970
triton_client.start_stream(callback=partial(callback, user_data))
@@ -83,7 +84,7 @@ def test_batch_error(self):
8384

8485
for i in range(number_of_requests):
8586
result = user_data._completed_requests.get()
86-
if i == 0:
87+
if i == 0 or i == 2:
8788
self.assertIs(type(result), InferenceServerException)
8889
continue
8990

@@ -139,7 +140,8 @@ def test_incorrect_execute_return(self):
139140
self.assertTrue(
140141
"Failed to process the request(s) for model instance "
141142
"'execute_return_error_0', message: Expected a list in the "
142-
"execute return" in str(e.exception), "Exception message is not correct.")
143+
"execute return" in str(e.exception),
144+
"Exception message is not correct.")
143145

144146
# The second inference request will return a list of None object
145147
# instead of Python InferenceResponse objects.
@@ -150,7 +152,8 @@ def test_incorrect_execute_return(self):
150152
"Failed to process the request(s) for model instance "
151153
"'execute_return_error_0', message: Expected an "
152154
"'InferenceResponse' object in the execute function return"
153-
" list" in str(e.exception), "Exception message is not correct.")
155+
" list" in str(e.exception),
156+
"Exception message is not correct.")
154157

155158

156159
if __name__ == '__main__':

qa/python_models/execute_error/model.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
1+
# Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -34,7 +34,7 @@ def execute(self, requests):
3434
"""
3535
responses = []
3636

37-
# Only generate the error for the first request
37+
# Generate the error for the first and third request
3838
i = 0
3939
for request in requests:
4040
input_tensor = pb_utils.get_input_tensor_by_name(request, "IN")
@@ -44,8 +44,12 @@ def execute(self, requests):
4444
'An error occured during execution')
4545
responses.append(pb_utils.InferenceResponse([out_tensor],
4646
error))
47-
else:
47+
elif i == 1:
4848
responses.append(pb_utils.InferenceResponse([out_tensor]))
49+
elif i == 2:
50+
error = pb_utils.TritonError(
51+
'An error occured during execution')
52+
responses.append(pb_utils.InferenceResponse(error=error))
4953
i += 1
5054

5155
return responses

0 commit comments

Comments
 (0)