forked from lavina/lavina
1
0
Fork 0

fix server message serialization tests

This commit is contained in:
Nikita Vilunov 2023-02-12 13:15:31 +01:00
parent e59e9386a8
commit bd63732e25
3 changed files with 25 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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<()>,

16
src/util/testkit.rs Normal file
View File

@ -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"))
}
}