Limit block!() macro to a finite amount of time
Previously, the block!() macro would loop forever, which would hang
tests. This modifies it such that it will block for a while, but
eventually end, causing a test failure.
@@ -150,8 +150,11 @@ pub mod tests {
}
macro_rules! block {
- ($op:expr, $err:ident) => {
+ ($op:expr, $err:ident) => {{
+ let start = Instant::now();
+ let duration = Duration::from_millis(60000); // 60 seconds
loop {
+ assert!(start.elapsed() < duration, "blocked for too long");
match $op {
Err($err::WouldBlock) => {
thread::sleep(Duration::from_millis(100));
@@ -161,7 +164,7 @@ pub mod tests {
Ok(ok) => break Ok(ok),
}
}
- };
+ }};
}
pub fn test_transport<T: Transport + Send + 'static>(mut transport: T, bind: &str) {
