Browse Source

Use LogHandler in testing Server tests.

wip
Titouan Rigoudy 4 years ago
parent
commit
ca9b1db296
1 changed files with 16 additions and 13 deletions
  1. +16
    -13
      proto/src/server/testing.rs

+ 16
- 13
proto/src/server/testing.rs View File

@ -364,6 +364,16 @@ impl RequestHandler for LogHandler {
}
}
pub struct LogHandlerFactory;
impl ClientHandlerFactory for LogHandlerFactory {
type Handler = LogHandler;
fn make(&self) -> Self::Handler {
LogHandler
}
}
// USER STATUS HANDLER
/// A map of user names to user status responses to serve.
@ -453,7 +463,9 @@ impl UserStatusHandlerFactory {
mod tests {
use tokio::net::TcpStream;
use super::{ServerBuilder, ShutdownType, UserStatusHandlerFactory};
use super::{
LogHandlerFactory, ServerBuilder, ShutdownType, UserStatusHandlerFactory,
};
// Enable capturing logs in tests.
fn init() {
@ -465,10 +477,7 @@ mod tests {
init();
let (server, handle) =
ServerBuilder::new(UserStatusHandlerFactory::default())
.bind()
.await
.unwrap();
ServerBuilder::new(LogHandlerFactory).bind().await.unwrap();
assert!(server.address().unwrap().ip().is_loopback());
assert_eq!(server.address().unwrap(), handle.address());
}
@ -478,10 +487,7 @@ mod tests {
init();
let (server, handle) =
ServerBuilder::new(UserStatusHandlerFactory::default())
.bind()
.await
.unwrap();
ServerBuilder::new(LogHandlerFactory).bind().await.unwrap();
let server_task = tokio::spawn(server.serve());
// The connection succeeds.
@ -501,10 +507,7 @@ mod tests {
init();
let (mut server, handle) =
ServerBuilder::new(UserStatusHandlerFactory::default())
.bind()
.await
.unwrap();
ServerBuilder::new(LogHandlerFactory).bind().await.unwrap();
// The connection is accepted, then immediately closed.
let address = handle.address();


Loading…
Cancel
Save