MCPcopy Index your code
hub / github.com/NVIDIA/TensorRT-LLM / test_task_error

Method test_task_error

tests/unittest/executor/test_rpc.py:254–302  ·  view source on GitHub ↗

Test that server-side exceptions are properly wrapped in RPCError with details.

(self)

Source from the content-addressed store, hash-verified

252 pass
253
254 def test_task_error(self):
255 """Test that server-side exceptions are properly wrapped in RPCError with details."""
256
257 class App:
258
259 def hello(self):
260 raise ValueError("Test error message")
261
262 def divide_by_zero(self):
263 return 1 / 0
264
265 def custom_exception(self):
266 raise TestRpcError.CustomError("Custom error occurred")
267
268 addr = get_unique_ipc_addr()
269 with RPCServer(App()) as server:
270 server.bind(addr)
271 server.start()
272 time.sleep(0.1)
273 with RPCClient(addr) as client:
274 # Test ValueError handling
275 with pytest.raises(RPCError) as exc_info:
276 client.hello().remote()
277
278 error = exc_info.value
279 assert "Test error message" in str(error)
280 assert error.cause is not None
281 assert isinstance(error.cause, ValueError)
282 assert error.traceback is not None
283 assert "ValueError: Test error message" in error.traceback
284
285 # Test ZeroDivisionError handling
286 with pytest.raises(RPCError) as exc_info:
287 client.divide_by_zero().remote()
288
289 error = exc_info.value
290 assert "division by zero" in str(error)
291 assert error.cause is not None
292 assert isinstance(error.cause, ZeroDivisionError)
293 assert error.traceback is not None
294
295 # Test custom exception handling
296 with pytest.raises(RPCError) as exc_info:
297 client.custom_exception().remote()
298
299 error = exc_info.value
300 assert "Custom error occurred" in str(error)
301 assert error.cause is not None
302 assert error.traceback is not None
303
304 def test_shutdown_cancelled_error(self):
305 """Test that pending requests are cancelled with RPCCancelled when server shuts down."""

Callers

nothing calls this directly

Calls 11

get_unique_ipc_addrFunction · 0.90
RPCServerClass · 0.90
RPCClientClass · 0.90
bindMethod · 0.80
sleepMethod · 0.80
remoteMethod · 0.80
divide_by_zeroMethod · 0.80
custom_exceptionMethod · 0.80
AppClass · 0.70
startMethod · 0.45
helloMethod · 0.45

Tested by

no test coverage detected