54 / 65 · 14 API Testing Fundamentals · gRPC Fundamentals← prev⊞ allnext →☰ Read as one page
7.7Streaming
gRPC supports four communication patterns:
| Pattern | Description | Use Case |
|---|---|---|
| Unary | Client sends one request, server sends one response | Standard CRUD |
| Server streaming | Client sends one request, server sends stream of responses | Live feed, log tailing |
| Client streaming | Client sends stream of requests, server sends one response | File upload, batch processing |
| Bidirectional | Both sides send streams simultaneously | Chat, real-time collaboration |
Testing Server Streaming
def test_server_streaming(user_service):
"""Server streams all users matching a query."""
request = user_pb2.ListUsersRequest(page=1, per_page=100)
users = []
for response in user_service.StreamUsers(request):
users.append(response)
assert len(users) > 0
assert all(hasattr(u, "name") for u in users)