1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#![cfg(all(
feature = "managed",
any(feature = "rt_tokio_1", feature = "rt_async-std_1")
))]
use std::{convert::Infallible, future::Future, pin::Pin, task, time::Duration};
use deadpool::{
managed::{self, Metrics, Object, PoolConfig, PoolError, RecycleResult, Timeouts},
Runtime,
};
type Pool = managed::Pool<Manager, Object<Manager>>;
struct Manager {}
struct Never;
impl Future for Never {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
task::Poll::Pending
}
}
impl managed::Manager for Manager {
type Type = usize;
type Error = Infallible;
async fn create(&self) -> Result<usize, Infallible> {
Never.await;
unreachable!();
}
async fn recycle(&self, _conn: &mut usize, _: &Metrics) -> RecycleResult<Infallible> {
Never.await;
unreachable!();
}
}
async fn test_managed_timeout(runtime: Runtime) {
let mgr = Manager {};
let cfg = PoolConfig {
max_size: 16,
timeouts: Timeouts {
create: Some(Duration::from_millis(0)),
wait: Some(Duration::from_millis(0)),
recycle: Some(Duration::from_millis(0)),
},
..Default::default()
};
let pool = Pool::builder(mgr)
.config(cfg)
.runtime(runtime)
.build()
.unwrap();
assert!(matches!(pool.get().await, Err(PoolError::Timeout(_))));
}
#[cfg(feature = "rt_tokio_1")]
#[tokio::test]
async fn rt_tokio_1() {
test_managed_timeout(Runtime::Tokio1).await;
}
#[cfg(feature = "rt_async-std_1")]
#[async_std::test]
async fn rt_async_std_1() {
test_managed_timeout(Runtime::AsyncStd1).await;
}
|