55 / 65 · 14 API Testing Fundamentals · gRPC Fundamentals← prev⊞ allnext →☰ Read as one page
7.8Deadline/Timeout Testing
gRPC has built-in deadline propagation — a client can set a deadline, and if the server does not respond in time, the call fails.
def test_deadline_exceeded(user_service):
"""Request with very short deadline should fail."""
request = user_pb2.GetUserRequest(id="123")
with pytest.raises(grpc.RpcError) as exc_info:
# 1 microsecond deadline — guaranteed to fail
user_service.GetUser(request, timeout=0.000001)
assert exc_info.value.code() == grpc.StatusCode.DEADLINE_EXCEEDED