Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of using a server as the GrpcService in a client #2227

Open
kjvalencik opened this issue Mar 20, 2025 · 0 comments
Open

Example of using a server as the GrpcService in a client #2227

kjvalencik opened this issue Mar 20, 2025 · 0 comments

Comments

@kjvalencik
Copy link

kjvalencik commented 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 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?

@kjvalencik 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant