hyperium / tonic

A native gRPC client & server implementation with async/await support.
https://docs.rs/tonic
MIT License
9.35k stars 957 forks source link

Add a way to test/inspect server and router build/configuration #1679

Open egtwp opened 3 months ago

egtwp commented 3 months ago

Feature Request

Motivation

For example, let's say I want to parse a configuration file to build my tonic server:

   // Let's exclude the file parsing code since it's not the focus here
   struct MyTonicConfig {
        http1: bool,
        concurrency_limit: Option<usize>,
        keep_alive: Option<std::time::Duration>,
    }

    fn build_tonic_by_config(config: MyTonicConfig) -> tonic::transport::Server {
        let mut my_tonic_server = Server::builder();

        if config.http1 {
            my_tonic_server = my_tonic_server.accept_http1(true);
        }

        if let Some(concurrency_limit) = config.concurrency_limit {
            my_tonic_server = my_tonic_server.concurrency_limit_per_connection(concurrency_limit);
        }

        my_tonic_server = my_tonic_server.http2_keepalive_timeout(config.keep_alive);

        my_tonic_server
    }

I would like to be able to inspect the resulting tonic server to be sure my code is working as expected, but I can't find any getter for tonic::transportation::Server fields.

Similar, but I think more complicated, scenario I think is applicable for Router and Routes.

Proposal

The simplest solution I can think is to add getters for tonic::transportaion:Server

Alternatives

  1. Implement an "expect" like method that can compare tonic::transportaion:Server fields value with given test value.
  2. Implement PartialEq/Eq for tonic::transportaion:Server