diff --git a/src/common/mod.rs b/src/common/mod.rs index 6fae8c6..b211b8c 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -170,10 +170,10 @@ pub enum ServerError { Overflow, /// Server maximum capacity has been reached. ServerFull, - /// Underflow occurred while processing messages. - Underflow, /// Shutdown requested. ShutdownEvent, + /// Underflow occurred while processing messages. + Underflow, } impl Display for ServerError { @@ -348,6 +348,23 @@ mod tests { } } + impl PartialEq for ServerError { + fn eq(&self, other: &Self) -> bool { + use self::ServerError::*; + match (self, other) { + (ConnectionError(ref e), ConnectionError(ref other_e)) => e.eq(other_e), + (IOError(ref e), IOError(ref other_e)) => { + e.raw_os_error() == other_e.raw_os_error() + } + (Overflow, Overflow) => true, + (ServerFull, ServerFull) => true, + (ShutdownEvent, ShutdownEvent) => true, + (Underflow, Underflow) => true, + _ => false, + } + } + } + #[test] fn test_version() { // Tests for raw() diff --git a/src/server.rs b/src/server.rs index 9809310..2eff27f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1151,11 +1151,11 @@ mod tests { handler.join().unwrap(); // Expect shutdown event instead of http request event. - match &*request_result.lock().unwrap() { - Err(ServerError::ShutdownEvent) => (), - v => { - panic!("Expected shutdown event, instead got {:?}.", v) - } - }; + let res = request_result.lock().unwrap(); + assert_eq!( + res.as_ref().unwrap_err(), + &ServerError::ShutdownEvent, + "Expected shutdown event, instead got {res:?}" + ); } }