|
|
|
@ -137,7 +137,7 @@ impl GracefulHandler { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A builder for FakeServer instances.
|
|
|
|
/// A builder for Server instances.
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct ServerBuilder {
|
|
|
|
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.
|
|
|
|
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 address = listener.local_addr()?;
|
|
|
|
|
|
|
|
@ -164,12 +164,12 @@ impl ServerBuilder { |
|
|
|
let (shutdown_tx, shutdown_rx) = watch::channel(());
|
|
|
|
|
|
|
|
Ok((
|
|
|
|
FakeServer {
|
|
|
|
Server {
|
|
|
|
listener,
|
|
|
|
shutdown_rx,
|
|
|
|
user_status_map,
|
|
|
|
},
|
|
|
|
FakeServerHandle {
|
|
|
|
ServerHandle {
|
|
|
|
shutdown_tx,
|
|
|
|
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,
|
|
|
|
shutdown_rx: watch::Receiver<()>,
|
|
|
|
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<()>,
|
|
|
|
address: SocketAddr,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FakeServerHandle {
|
|
|
|
impl ServerHandle {
|
|
|
|
/// Returns the address on which the server is accepting connections.
|
|
|
|
pub fn address(&self) -> SocketAddr {
|
|
|
|
self.address
|
|
|
|
@ -205,7 +204,7 @@ impl FakeServerHandle { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FakeServer {
|
|
|
|
impl Server {
|
|
|
|
/// Returns the address to which this server is bound.
|
|
|
|
/// This is always localhost and a random port chosen by the OS.
|
|
|
|
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.
|
|
|
|
for task in handler_tasks {
|
|
|
|
|