mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 21:37:58 +03:00
Remove Deref for Container<T> (#212)
This commit is contained in:
parent
108e2ac20a
commit
50528b11ff
5 changed files with 35 additions and 37 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [1.2.0-beta.2] - 2023-06-19
|
||||
|
||||
* Remove Deref for Container<T>
|
||||
|
||||
## [1.2.0-beta.1] - 2023-06-19
|
||||
|
||||
* Rename Ctx to ServiceCtx
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-service"
|
||||
version = "1.2.0-beta.1"
|
||||
version = "1.2.0-beta.2"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "ntex service"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
use std::{
|
||||
cell::UnsafeCell, future::Future, marker, ops, pin::Pin, rc::Rc, task, task::Poll,
|
||||
};
|
||||
use std::{cell::UnsafeCell, future::Future, marker, pin::Pin, rc::Rc, task, task::Poll};
|
||||
|
||||
use crate::{Service, ServiceFactory};
|
||||
|
||||
|
@ -73,6 +71,11 @@ impl<S> Container<S> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return reference to inner type
|
||||
pub fn get_ref(&self) -> &S {
|
||||
self.svc.as_ref()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns `Ready` when the service is able to process requests.
|
||||
pub fn poll_ready<R>(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), S::Error>>
|
||||
|
@ -142,15 +145,6 @@ impl<S> From<S> for Container<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> ops::Deref for Container<S> {
|
||||
type Target = S;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &S {
|
||||
self.svc.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S: ?Sized> ServiceCtx<'a, S> {
|
||||
pub(crate) fn new(waiters: &'a Waiters) -> Self {
|
||||
Self {
|
||||
|
|
|
@ -52,7 +52,7 @@ ntex-codec = "0.6.2"
|
|||
ntex-connect = "0.3.0-beta.1"
|
||||
ntex-http = "0.1.9"
|
||||
ntex-router = "0.5.1"
|
||||
ntex-service = "1.2.0-beta.1"
|
||||
ntex-service = "1.2.0-beta.2"
|
||||
ntex-macros = "0.1.3"
|
||||
ntex-util = "0.3.0-beta.1"
|
||||
ntex-bytes = "0.1.19"
|
||||
|
|
|
@ -664,49 +664,49 @@ mod tests {
|
|||
assert_eq!(store.borrow().len(), 1);
|
||||
assert!(format!("{:?}", conn).contains("H1Connection"));
|
||||
assert_eq!(conn.protocol(), HttpProtocol::Http1);
|
||||
assert_eq!(pool.inner.borrow().acquired, 1);
|
||||
assert!(pool.inner.borrow().connecting.is_empty());
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 1);
|
||||
assert!(pool.get_ref().inner.borrow().connecting.is_empty());
|
||||
|
||||
// pool is full, waiting
|
||||
let mut fut = pool.call(req.clone());
|
||||
assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending());
|
||||
assert_eq!(pool.waiters.borrow().waiters.len(), 1);
|
||||
assert_eq!(pool.get_ref().waiters.borrow().waiters.len(), 1);
|
||||
|
||||
// release connection and push it to next waiter
|
||||
conn.release(false);
|
||||
assert_eq!(pool.inner.borrow().acquired, 0);
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 0);
|
||||
let _conn = fut.await.unwrap();
|
||||
assert_eq!(store.borrow().len(), 1);
|
||||
assert!(pool.waiters.borrow().waiters.is_empty());
|
||||
assert!(pool.get_ref().waiters.borrow().waiters.is_empty());
|
||||
drop(_conn);
|
||||
|
||||
// close connnection
|
||||
let conn = pool.call(req.clone()).await.unwrap();
|
||||
assert_eq!(store.borrow().len(), 2);
|
||||
assert_eq!(pool.inner.borrow().acquired, 1);
|
||||
assert!(pool.inner.borrow().connecting.is_empty());
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 1);
|
||||
assert!(pool.get_ref().inner.borrow().connecting.is_empty());
|
||||
let mut fut = pool.call(req.clone());
|
||||
assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending());
|
||||
assert_eq!(pool.waiters.borrow().waiters.len(), 1);
|
||||
assert_eq!(pool.get_ref().waiters.borrow().waiters.len(), 1);
|
||||
|
||||
// release and close
|
||||
conn.release(true);
|
||||
assert_eq!(pool.inner.borrow().acquired, 0);
|
||||
assert!(pool.inner.borrow().connecting.is_empty());
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 0);
|
||||
assert!(pool.get_ref().inner.borrow().connecting.is_empty());
|
||||
|
||||
let conn = fut.await.unwrap();
|
||||
assert_eq!(store.borrow().len(), 3);
|
||||
assert!(pool.waiters.borrow().waiters.is_empty());
|
||||
assert!(pool.inner.borrow().connecting.is_empty());
|
||||
assert_eq!(pool.inner.borrow().acquired, 1);
|
||||
assert!(pool.get_ref().waiters.borrow().waiters.is_empty());
|
||||
assert!(pool.get_ref().inner.borrow().connecting.is_empty());
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 1);
|
||||
|
||||
// drop waiter, no interest in connection
|
||||
let mut fut = pool.call(req.clone());
|
||||
assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending());
|
||||
drop(fut);
|
||||
sleep(Millis(50)).await;
|
||||
pool.inner.borrow_mut().check_availibility();
|
||||
assert!(pool.waiters.borrow().waiters.is_empty());
|
||||
pool.get_ref().inner.borrow_mut().check_availibility();
|
||||
assert!(pool.get_ref().waiters.borrow().waiters.is_empty());
|
||||
|
||||
// different uri
|
||||
let req = Connect {
|
||||
|
@ -715,19 +715,19 @@ mod tests {
|
|||
};
|
||||
let mut fut = pool.call(req.clone());
|
||||
assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending());
|
||||
assert_eq!(pool.waiters.borrow().waiters.len(), 1);
|
||||
assert_eq!(pool.get_ref().waiters.borrow().waiters.len(), 1);
|
||||
conn.release(false);
|
||||
assert_eq!(pool.inner.borrow().acquired, 0);
|
||||
assert_eq!(pool.inner.borrow().available.len(), 1);
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 0);
|
||||
assert_eq!(pool.get_ref().inner.borrow().available.len(), 1);
|
||||
|
||||
let conn = fut.await.unwrap();
|
||||
assert_eq!(store.borrow().len(), 4);
|
||||
assert!(pool.waiters.borrow().waiters.is_empty());
|
||||
assert!(pool.inner.borrow().connecting.is_empty());
|
||||
assert_eq!(pool.inner.borrow().acquired, 1);
|
||||
assert!(pool.get_ref().waiters.borrow().waiters.is_empty());
|
||||
assert!(pool.get_ref().inner.borrow().connecting.is_empty());
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 1);
|
||||
conn.release(false);
|
||||
assert_eq!(pool.inner.borrow().acquired, 0);
|
||||
assert_eq!(pool.inner.borrow().available.len(), 2);
|
||||
assert_eq!(pool.get_ref().inner.borrow().acquired, 0);
|
||||
assert_eq!(pool.get_ref().inner.borrow().available.len(), 2);
|
||||
|
||||
assert!(lazy(|cx| pool.poll_ready(cx)).await.is_ready());
|
||||
assert!(lazy(|cx| pool.poll_shutdown(cx)).await.is_ready());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue