Browse Source

Rename FakeServer to Server, same with ServerHandle.

wip
Titouan Rigoudy 5 years ago
parent
commit
9a7849c692
1 changed files with 11 additions and 12 deletions
  1. +11
    -12
      src/proto/server/testing.rs

+ 11
- 12
src/proto/server/testing.rs View File

@ -137,7 +137,7 @@ impl GracefulHandler {
} }
} }
/// A builder for FakeServer instances.
/// A builder for Server instances.
#[derive(Default)] #[derive(Default)]
pub struct ServerBuilder { pub struct ServerBuilder {
user_status_map: Option<Arc<Mutex<UserStatusMap>>>, user_status_map: Option<Arc<Mutex<UserStatusMap>>>,
@ -152,7 +152,7 @@ impl ServerBuilder {
} }
/// Binds to a localhost port, then returns a server and its handle. /// Binds to a localhost port, then returns a server and its handle.
pub async fn bind(self) -> io::Result<(FakeServer, FakeServerHandle)> {
pub async fn bind(self) -> io::Result<(Server, ServerHandle)> {
let listener = TcpListener::bind("localhost:0").await?; let listener = TcpListener::bind("localhost:0").await?;
let address = listener.local_addr()?; let address = listener.local_addr()?;
@ -164,12 +164,12 @@ impl ServerBuilder {
let (shutdown_tx, shutdown_rx) = watch::channel(()); let (shutdown_tx, shutdown_rx) = watch::channel(());
Ok(( Ok((
FakeServer {
Server {
listener, listener,
shutdown_rx, shutdown_rx,
user_status_map, user_status_map,
}, },
FakeServerHandle {
ServerHandle {
shutdown_tx, shutdown_tx,
address, address,
}, },
@ -177,21 +177,20 @@ impl ServerBuilder {
} }
} }
// TODO: Rename all FakeServer* to Server*.
/// A fake server for connecting to in tests.
pub struct FakeServer {
/// A simple server for connecting to in tests.
pub struct Server {
listener: TcpListener, listener: TcpListener,
shutdown_rx: watch::Receiver<()>, shutdown_rx: watch::Receiver<()>,
user_status_map: Arc<Mutex<UserStatusMap>>, user_status_map: Arc<Mutex<UserStatusMap>>,
} }
/// Allows interacting with a running `FakeServer`.
pub struct FakeServerHandle {
/// Allows interacting with a running `Server`.
pub struct ServerHandle {
shutdown_tx: watch::Sender<()>, shutdown_tx: watch::Sender<()>,
address: SocketAddr, address: SocketAddr,
} }
impl FakeServerHandle {
impl ServerHandle {
/// Returns the address on which the server is accepting connections. /// Returns the address on which the server is accepting connections.
pub fn address(&self) -> SocketAddr { pub fn address(&self) -> SocketAddr {
self.address self.address
@ -205,7 +204,7 @@ impl FakeServerHandle {
} }
} }
impl FakeServer {
impl Server {
/// Returns the address to which this server is bound. /// Returns the address to which this server is bound.
/// This is always localhost and a random port chosen by the OS. /// This is always localhost and a random port chosen by the OS.
pub fn address(&self) -> io::Result<SocketAddr> { pub fn address(&self) -> io::Result<SocketAddr> {
@ -244,7 +243,7 @@ impl FakeServer {
); );
} }
info!("FakeServer: shutting down");
info!("Server: shutting down");
// TODO: pass results back instead through an mpsc channel. // TODO: pass results back instead through an mpsc channel.
for task in handler_tasks { for task in handler_tasks {


Loading…
Cancel
Save