Considerations for Testing gRPC Streams
If you’ve spent any time building cloud-native systems, you’ve probably tripped over the tricky beast that is gRPC streaming. It’s powerful, flexible, and feels like magic when it works. But the minute you need to test it? Suddenly, you’re in “hold my coffee, I need a week” territory.
One of the most common places we see gRPC streams in the wild is when clients connect to asynchronous message buses like Google Pub/Sub. It’s a natural fit: Pub/Sub shovels messages at you as fast as your subscriber can handle them, and gRPC streams provide the async plumbing to get them from point A to B.
The question is: how do you test this without turning your CI pipeline into a distributed systems research project?
Deciding What to Test
When mocking or testing gRPC streams, the first decision is what belongs in your test.
- Do you want a unit or isolation test of just your gRPC client logic?
- Or do you want to run a system test that simulates the whole “Pub/Sub → gRPC stream → your app” pipeline?

If you’re testing the client code itself, mocking the gRPC server makes sense. You can simulate message arrival, stream ordering, and retry logic without pulling in an actual Pub/Sub topic. This is fast, lightweight, and works great when you want to exercise logic in isolation.
For provider-owned behavior, keep a real test bus in scope. Both producers and consumers can need it; choose the boundary from the question being tested. A local emulator is useful too, but its documented omissions matter.
Why Test with Real Pub/Sub?
Using Pub/Sub as part of your load test brings realism that mocks just can’t replicate. For example:
- Backpressure and bottlenecks - Pub/Sub enforces quotas, and each subscriber caps its outstanding messages with client-side flow control. If your subscribers can’t keep up, Pub/Sub keeps accepting messages and the backlog grows. Watching that backlog and the age of the oldest unacknowledged message is the production-like signal you want in testing.
- Operational quirks - Messages may arrive slightly out of order, be redelivered, or trigger retries. If your system can’t handle that, better to find out now than on a Friday night during an incident.
- Scale dynamics - Spinning up multiple subscribers against a real Pub/Sub topic is often the only way to flush out hidden resource contention issues.
Use a real test topic for the broker semantics or capacity you intend to measure, with test identities and a defined workload. A successful client-side mock test answers a narrower question.
But What About Mocks?
Of course, not every test needs (or can afford) to spin up a real Pub/Sub topic. That’s where mocks and simulators shine.
proxymock records a Pub/Sub subscriber’s traffic, including the StreamingPull stream it keeps open for hours and ends by cancelling. It can then use that recording two ways:
- Mock the subscriber’s Pub/Sub. The mock answers
StreamingPullandPullfrom the messages recorded for the subscription, at the pace they arrived or scaled faster or slower, and honors the client’smax_outstanding_messagesandmax_outstanding_bytes. It answersAcknowledgeandModifyAckDeadlineitself, so your subscriber runs with no Google Cloud project and no emulator. - Drive a real subscriber by republishing. A replay can publish every recorded message back to the subscription’s topic, on a test project or the emulator, at the recorded gaps or scaled up with more virtual users. Your subscriber then receives and acknowledges them itself.
This is not a full Pub/Sub implementation. The mock redelivers a message your subscriber nacks or lets expire, so a recording can test your retry path, but it does not simulate exactly-once delivery, enforce ordering-key delivery rules, or provide a dead-letter topic. The Google Pub/Sub guide lists what is supported.
Think of it like flight training: sometimes you fly the real plane, but sometimes you practice stalling and engine-out maneuvers in the simulator. Both are valuable, but you don’t want to mix them up.
The Testing Strategy That Works
So how do you balance mocks and real systems?
- Unit tests → Mock gRPC streams directly. Keep it fast and focused.
- System tests → Include Google Pub/Sub in the loop. Let it be the source of truth and the source of bottlenecks.
- Load testing a subscriber → Republish recorded messages to a test topic at production pace, then scale it, and watch the subscription’s backlog.
- Chaos testing → Use a controllable server or test service that can delay messages, drop the stream, and fail acknowledgements on demand.
That way, you get coverage across the spectrum without burning out your team, or your budget.
Run this workflow with an LLM
Give this prompt to a coding assistant with access to your project and this article. Supply environment-specific values it cannot discover.
Whole-workflow LLM prompt
Read https://speedscale.com/blog/considerations-for-testing-grpc-streams/ and inspect my project instructions first. Add local gRPC stream tests for my service's actual stream type. Cover message order, partial completion, cancellation, deadline, and non-OK final status. Use bounded synthetic sequences, assert client behavior, and avoid treating an HTTP 200 as stream success. Check installed tool help before adapting commands. Report the checks actually run, their results, and anything you could not verify.
Final Thoughts
gRPC streams are awesome, but testing them doesn’t have to be painful. By mixing real message buses like Pub/Sub into your system tests and leveraging simulators like proxymock for targeted scenarios, you get the best of both worlds: realism where it counts, mocks where it helps.
If you’re ready to stop wrestling with gRPC stream mocks and start running reliable, repeatable tests, try proxymock with the Google Pub/Sub guide and keep real-bus checks for the behaviors it excludes.
Frequently asked questions
When should I keep the real message bus in a streaming test?
Keep a real test instance when the question concerns provider IAM, quotas, acknowledgment deadlines, redelivery, ordering configuration, or capacity. A simulator can exercise selected client reactions, while an emulator supports another useful local boundary with documented omissions. Choose from the behavior under test rather than assuming that producers always need the provider and consumers never do.
How do I test cancellation, reconnects, and backpressure?
Use a controllable server or test service that can delay messages, terminate a connection, and observe cancellation. Assert bounded retries, resource cleanup, and recovery without unintended duplicate processing. Exercise slow consumers and sustained outstanding work. Inspect application queues as well as transport flow control; a completed write does not necessarily mean the peer consumed the message.
Which streaming behavior can a recorded mock reproduce?
For a Google Pub/Sub subscriber, proxymock serves the long-lived bidirectional StreamingPull stream from the recorded messages: their data, attributes and ordering keys, at the recorded pace or scaled faster or slower, within the flow control the client asks for, with acknowledgements freeing room. It redelivers a message your subscriber nacks or lets expire, with the next delivery attempt. It does not simulate exactly-once delivery, enforce ordering-key delivery rules, or provide a dead-letter topic, so keep a real test subscription for those.
Sources: Pub/Sub emulator limitations, Pub/Sub delivery and flow control, gRPC cancellation, gRPC flow control, gRPC deadlines, Speedscale Google Pub/Sub guide, Long-lived gRPC streams.