You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to write some end-to-end tests for code that uses a tonic client. I wanted to have a mock server without needing to mock the gRPC client.
I started with the mock example which uses a duplex stream for in-process I/O, but that felt overly complicated. I then started looking at the GrpcService trait and creating an implementation that would use my mock server directly.
While writing that implementation, I discovered that tonic servers already implement this trait. You can simply pass a server to a client and it works.
let server = GreetServiceServer::new(Greeter::default());let client = GreetServiceClient::new(server);
I couldn't find any examples of this pattern in the repo and it's very handy for testing.
Would you be willing to accept a PR to add an example demonstrating this? Would it be preferable to replace the mock example with this pattern?
The text was updated successfully, but these errors were encountered:
kjvalencik
changed the title
Provide an example of using a tonic server as the GrpcService in a client
Example of using a server as the GrpcService in a client
Mar 20, 2025
I wanted to write some end-to-end tests for code that uses a tonic client. I wanted to have a mock server without needing to mock the gRPC client.
I started with the
mock
example which uses a duplex stream for in-process I/O, but that felt overly complicated. I then started looking at theGrpcService
trait and creating an implementation that would use my mock server directly.While writing that implementation, I discovered that tonic servers already implement this trait. You can simply pass a server to a client and it works.
I couldn't find any examples of this pattern in the repo and it's very handy for testing.
Would you be willing to accept a PR to add an example demonstrating this? Would it be preferable to replace the
mock
example with this pattern?The text was updated successfully, but these errors were encountered: