Skip to main content

MockProtocolServer

Trait MockProtocolServer 

Source
pub trait MockProtocolServer: Send + Sync {
    // Required methods
    fn protocol(&self) -> Protocol;
    fn start<'life0, 'async_trait>(
        &'life0 self,
        shutdown: Receiver<()>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn port(&self) -> u16;
    fn description(&self) -> String;
}
Expand description

Trait for mock protocol server lifecycle management.

Each protocol crate implements this to provide a uniform startup interface. The CLI can collect Box<dyn MockProtocolServer> instances and launch them all through a single code path, rather than having bespoke startup logic for each protocol.

Implementations should:

  • Wrap existing server startup code (not rewrite it)
  • Run until the shutdown signal is received in start
  • Return errors from start if the server fails to bind or encounters a fatal error

Required Methods§

Source

fn protocol(&self) -> Protocol

Which protocol this server handles.

Source

fn start<'life0, 'async_trait>( &'life0 self, shutdown: Receiver<()>, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the server, running until the shutdown signal is received.

The server should listen on its configured address and handle requests until the shutdown receiver signals (i.e., the sender is dropped or a value is sent). Implementations should use tokio::select! to combine the server’s accept loop with the shutdown signal.

§Errors

Returns an error if the server fails to bind, encounters a fatal I/O error, or any other unrecoverable condition.

Source

fn port(&self) -> u16

The port this server is listening on.

Source

fn description(&self) -> String

Human-readable description for logging (e.g., “gRPC server on port 50051”).

Implementors§