This commit is contained in:
Nikolay Kim 2024-11-03 12:17:55 +05:00
parent bc2ac87a9b
commit 4d070bcee6
3 changed files with 21 additions and 17 deletions

View file

@ -93,7 +93,7 @@ mod tests {
use crate::{chain, chain_factory, fn_factory, Service, ServiceCtx};
#[derive(Clone)]
#[derive(Debug, Clone)]
struct Srv1(Rc<Cell<usize>>, Rc<Cell<usize>>);
impl Service<&'static str> for Srv1 {
@ -123,7 +123,7 @@ mod tests {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
struct Srv2(Rc<Cell<usize>>, Rc<Cell<usize>>);
impl Service<&'static str> for Srv2 {
@ -157,12 +157,10 @@ mod tests {
async fn test_ready() {
let cnt = Rc::new(Cell::new(0));
let cnt_sht = Rc::new(Cell::new(0));
let srv = Box::new(
chain(Srv1(cnt.clone(), cnt_sht.clone()))
.and_then(Srv2(cnt.clone(), cnt_sht.clone()))
.clone(),
)
.into_pipeline();
let srv = chain(Box::new(Srv1(cnt.clone(), cnt_sht.clone())))
.clone()
.and_then(crate::boxed::service(Srv2(cnt.clone(), cnt_sht.clone())))
.into_pipeline();
let res = srv.ready().await;
assert_eq!(res, Ok(()));
assert_eq!(cnt.get(), 2);
@ -176,6 +174,8 @@ mod tests {
srv.shutdown().await;
assert_eq!(cnt_sht.get(), 2);
assert!(format!("{:?}", srv).contains("AndThen"));
}
#[ntex::test]
@ -194,11 +194,9 @@ mod tests {
#[ntex::test]
async fn test_call() {
let cnt = Rc::new(Cell::new(0));
let srv = Box::new(
chain(Srv1(cnt.clone(), Rc::new(Cell::new(0))))
.and_then(Srv2(cnt, Rc::new(Cell::new(0)))),
)
.into_pipeline();
let srv = chain(Box::new(Srv1(cnt.clone(), Rc::new(Cell::new(0)))))
.and_then(Srv2(cnt, Rc::new(Cell::new(0))))
.into_pipeline();
let res = srv.call("srv1").await;
assert!(res.is_ok());
assert_eq!(res.unwrap(), ("srv1", "srv2"));

View file

@ -329,9 +329,10 @@ mod tests {
use crate::future::lazy;
use crate::task::LocalWaker;
#[derive(Clone)]
#[derive(Debug, Clone)]
struct TestService(Rc<Inner>);
#[derive(Debug)]
struct Inner {
ready: Cell<bool>,
waker: LocalWaker,
@ -423,6 +424,11 @@ mod tests {
assert_eq!(lazy(|cx| srv.poll_ready(cx)).await, Poll::Ready(Ok(())));
assert_eq!(lazy(|cx| srv.poll_not_ready(cx)).await, Poll::Pending);
assert!(lazy(|cx| srv.poll_shutdown(cx)).await.is_ready());
let err = BufferServiceError::from("test");
assert!(format!("{}", err).contains("test"));
assert!(format!("{:?}", srv).contains("BufferService"));
assert!(format!("{:?}", Buffer::<TestService>::default()).contains("Buffer"));
}
#[ntex_macros::rt_test2]

View file

@ -257,7 +257,7 @@ mod tests {
use super::*;
#[derive(Clone)]
#[derive(Debug, Clone)]
struct Srv1;
impl Service<()> for Srv1 {
@ -275,7 +275,7 @@ mod tests {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
struct Srv2;
impl Service<()> for Srv2 {
@ -303,9 +303,9 @@ mod tests {
.clone()
.v3(fn_factory(|| async { Ok::<_, ()>(Srv2) }))
.clone();
assert!(format!("{:?}", factory).contains("Variant"));
let service = factory.pipeline(&()).await.unwrap().clone();
assert!(format!("{:?}", service).contains("Variant"));
let mut f = pin::pin!(service.not_ready());
let _ = poll_fn(|cx| {