forked from lavina/lavina
fix server message serialization tests
This commit is contained in:
parent
e59e9386a8
commit
bd63732e25
|
@ -206,6 +206,7 @@ mod test {
|
|||
use assert_matches::*;
|
||||
|
||||
use super::*;
|
||||
use crate::util::testkit::*;
|
||||
|
||||
#[test]
|
||||
fn test_server_message_notice() {
|
||||
|
@ -224,7 +225,9 @@ mod test {
|
|||
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
||||
|
||||
let mut bytes = vec![];
|
||||
expected.write(&mut bytes).unwrap();
|
||||
sync_future(expected.write_async(&mut bytes))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(bytes, input);
|
||||
}
|
||||
|
||||
|
@ -244,7 +247,9 @@ mod test {
|
|||
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
||||
|
||||
let mut bytes = vec![];
|
||||
expected.write(&mut bytes).unwrap();
|
||||
sync_future(expected.write_async(&mut bytes))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(bytes, input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ use crate::prelude::*;
|
|||
pub mod http;
|
||||
pub mod table;
|
||||
pub mod telemetry;
|
||||
#[cfg(test)]
|
||||
pub mod testkit;
|
||||
|
||||
pub struct Terminator {
|
||||
signal: Sender<()>,
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
use std::task::{Context, Poll};
|
||||
|
||||
use futures_util::task::noop_waker_ref;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn sync_future<T>(future: impl Future<Output = T>) -> Result<T> {
|
||||
let waker = noop_waker_ref();
|
||||
let mut context = Context::from_waker(waker);
|
||||
pin!(future);
|
||||
if let Poll::Ready(a) = future.poll(&mut context) {
|
||||
Ok(a)
|
||||
} else {
|
||||
Err(anyhow::Error::msg("Future has suspended"))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue