mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 21:37:58 +03:00
cleanup tests
This commit is contained in:
parent
489ebb2aa0
commit
969799a1aa
4 changed files with 53 additions and 9 deletions
|
@ -315,10 +315,15 @@ mod tests {
|
||||||
#[ntex_rt::test]
|
#[ntex_rt::test]
|
||||||
async fn test_poll_ready() {
|
async fn test_poll_ready() {
|
||||||
let cnt = Rc::new(Cell::new(0));
|
let cnt = Rc::new(Cell::new(0));
|
||||||
let srv = pipeline(Srv1(cnt.clone())).and_then(Srv2(cnt.clone()));
|
let srv = pipeline(Srv1(cnt.clone()))
|
||||||
|
.and_then(Srv2(cnt.clone()))
|
||||||
|
.clone();
|
||||||
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
||||||
assert_eq!(res, Poll::Ready(Ok(())));
|
assert_eq!(res, Poll::Ready(Ok(())));
|
||||||
assert_eq!(cnt.get(), 2);
|
assert_eq!(cnt.get(), 2);
|
||||||
|
|
||||||
|
let res = lazy(|cx| srv.poll_shutdown(cx, false)).await;
|
||||||
|
assert_eq!(res, Poll::Ready(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ntex_rt::test]
|
#[ntex_rt::test]
|
||||||
|
@ -331,12 +336,13 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ntex_rt::test]
|
#[ntex_rt::test]
|
||||||
async fn test_new_service() {
|
async fn test_factory() {
|
||||||
let cnt = Rc::new(Cell::new(0));
|
let cnt = Rc::new(Cell::new(0));
|
||||||
let cnt2 = cnt.clone();
|
let cnt2 = cnt.clone();
|
||||||
let new_srv =
|
let new_srv =
|
||||||
pipeline_factory(fn_factory(move || ready(Ok::<_, ()>(Srv1(cnt2.clone())))))
|
pipeline_factory(fn_factory(move || ready(Ok::<_, ()>(Srv1(cnt2.clone())))))
|
||||||
.and_then(move || ready(Ok(Srv2(cnt.clone()))));
|
.and_then(move || ready(Ok(Srv2(cnt.clone()))))
|
||||||
|
.clone();
|
||||||
|
|
||||||
let srv = new_srv.new_service(()).await.unwrap();
|
let srv = new_srv.new_service(()).await.unwrap();
|
||||||
let res = srv.call("srv1").await;
|
let res = srv.call("srv1").await;
|
||||||
|
|
|
@ -312,15 +312,20 @@ mod tests {
|
||||||
|
|
||||||
#[ntex_rt::test]
|
#[ntex_rt::test]
|
||||||
async fn test_service() {
|
async fn test_service() {
|
||||||
let srv = pipeline(ok).and_then_apply_fn(Srv, |req: &'static str, s| {
|
let srv = pipeline(ok)
|
||||||
s.call(()).map_ok(move |res| (req, res))
|
.and_then_apply_fn(Srv, |req: &'static str, s| {
|
||||||
});
|
s.call(()).map_ok(move |res| (req, res))
|
||||||
|
})
|
||||||
|
.clone();
|
||||||
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
||||||
assert_eq!(res, Poll::Ready(Ok(())));
|
assert_eq!(res, Poll::Ready(Ok(())));
|
||||||
|
|
||||||
let res = srv.call("srv").await;
|
let res = srv.call("srv").await;
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
assert_eq!(res.unwrap(), ("srv", ()));
|
assert_eq!(res.unwrap(), ("srv", ()));
|
||||||
|
|
||||||
|
let res = lazy(|cx| srv.poll_shutdown(cx, false)).await;
|
||||||
|
assert_eq!(res, Poll::Ready(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ntex_rt::test]
|
#[ntex_rt::test]
|
||||||
|
@ -329,7 +334,8 @@ mod tests {
|
||||||
.and_then_apply_fn(
|
.and_then_apply_fn(
|
||||||
|| ok(Srv),
|
|| ok(Srv),
|
||||||
|req: &'static str, s| s.call(()).map_ok(move |res| (req, res)),
|
|req: &'static str, s| s.call(()).map_ok(move |res| (req, res)),
|
||||||
);
|
)
|
||||||
|
.clone();
|
||||||
let srv = new_srv.new_service(()).await.unwrap();
|
let srv = new_srv.new_service(()).await.unwrap();
|
||||||
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
||||||
assert_eq!(res, Poll::Ready(Ok(())));
|
assert_eq!(res, Poll::Ready(Ok(())));
|
||||||
|
|
|
@ -251,6 +251,34 @@ mod tests {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
.clone()
|
||||||
|
.new_service(())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(srv.call(10usize).await.unwrap(), 20);
|
||||||
|
assert_eq!(item.get(), 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[ntex_rt::test]
|
||||||
|
async fn test_apply_factory() {
|
||||||
|
let item = Rc::new(Cell::new(10usize));
|
||||||
|
let item2 = item.clone();
|
||||||
|
|
||||||
|
let srv = apply_cfg_factory(
|
||||||
|
fn_service(move |item: usize| ok::<_, ()>(item + 1)),
|
||||||
|
move |_: (), srv| {
|
||||||
|
let id = item2.get();
|
||||||
|
let fut = srv.call(id);
|
||||||
|
let item = item2.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
|
item.set(fut.await.unwrap());
|
||||||
|
Ok::<_, ()>(fn_service(|id: usize| ok::<_, ()>(id * 2)))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.clone()
|
||||||
.new_service(())
|
.new_service(())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -312,12 +312,14 @@ mod tests {
|
||||||
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
let res = lazy(|cx| srv.poll_ready(cx)).await;
|
||||||
assert_eq!(res, Poll::Ready(Err(())));
|
assert_eq!(res, Poll::Ready(Err(())));
|
||||||
assert_eq!(cnt.get(), 2);
|
assert_eq!(cnt.get(), 2);
|
||||||
|
let res = lazy(|cx| srv.poll_shutdown(cx, false)).await;
|
||||||
|
assert_eq!(res, Poll::Ready(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ntex_rt::test]
|
#[ntex_rt::test]
|
||||||
async fn test_call() {
|
async fn test_call() {
|
||||||
let cnt = Rc::new(Cell::new(0));
|
let cnt = Rc::new(Cell::new(0));
|
||||||
let srv = pipeline(Srv1(cnt.clone())).then(Srv2(cnt));
|
let srv = pipeline(Srv1(cnt.clone())).then(Srv2(cnt)).clone();
|
||||||
|
|
||||||
let res = srv.call(Ok("srv1")).await;
|
let res = srv.call(Ok("srv1")).await;
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
|
@ -333,7 +335,9 @@ mod tests {
|
||||||
let cnt = Rc::new(Cell::new(0));
|
let cnt = Rc::new(Cell::new(0));
|
||||||
let cnt2 = cnt.clone();
|
let cnt2 = cnt.clone();
|
||||||
let blank = move || ready(Ok::<_, ()>(Srv1(cnt2.clone())));
|
let blank = move || ready(Ok::<_, ()>(Srv1(cnt2.clone())));
|
||||||
let factory = pipeline_factory(blank).then(move || ready(Ok(Srv2(cnt.clone()))));
|
let factory = pipeline_factory(blank)
|
||||||
|
.then(move || ready(Ok(Srv2(cnt.clone()))))
|
||||||
|
.clone();
|
||||||
let srv = factory.new_service(&()).await.unwrap();
|
let srv = factory.new_service(&()).await.unwrap();
|
||||||
let res = srv.call(Ok("srv1")).await;
|
let res = srv.call(Ok("srv1")).await;
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue