Skip to content

fix #141 #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bb8/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl<M: ManageConnection> Builder<M> {
/// minimum number of connections, or it times out.
pub async fn build(self, manager: M) -> Result<Pool<M>, M::Error> {
let pool = self.build_inner(manager);
pool.inner.preconnect().await?;
pool.inner.start_connections().await.map(|()| pool)
}

Expand Down
4 changes: 4 additions & 0 deletions bb8/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ where
Ok(conn)
}

pub(crate) async fn preconnect(&self) -> Result<(), M::Error> {
self.inner.manager.connect().await.map(|_| ())
}

/// Return connection back in to the pool
pub(crate) fn put_back(&self, conn: Option<Conn<M::Connection>>) {
let conn = conn.and_then(|mut conn| {
Expand Down
12 changes: 6 additions & 6 deletions bb8/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where

#[tokio::test]
async fn test_max_size_ok() {
let manager = NthConnectionFailManager::<FakeConnection>::new(5);
let manager = NthConnectionFailManager::<FakeConnection>::new(6);
let pool = Pool::builder().max_size(5).build(manager).await.unwrap();
let mut channels = Vec::with_capacity(5);
let mut ignored = Vec::with_capacity(5);
Expand Down Expand Up @@ -409,7 +409,7 @@ async fn test_max_lifetime() {
}
}

let manager = NthConnectionFailManager::<Connection>::new(5);
let manager = NthConnectionFailManager::<Connection>::new(6);
let pool = Pool::builder()
.max_lifetime(Some(Duration::from_secs(1)))
.connection_timeout(Duration::from_secs(1))
Expand Down Expand Up @@ -442,14 +442,14 @@ async fn test_max_lifetime() {
assert!(timeout(Duration::from_secs(2), pending::<()>())
.await
.is_err());
assert_eq!(DROPPED.load(Ordering::SeqCst), 4);
assert_eq!(DROPPED.load(Ordering::SeqCst), 5);
tx2.send(()).unwrap();

// And wait some more.
assert!(timeout(Duration::from_secs(2), pending::<()>())
.await
.is_err());
assert_eq!(DROPPED.load(Ordering::SeqCst), 5);
assert_eq!(DROPPED.load(Ordering::SeqCst), 6);
}

#[tokio::test]
Expand Down Expand Up @@ -550,7 +550,7 @@ async fn test_conns_drop_on_pool_drop() {
drop(pool);

for _ in 0u8..10 {
if DROPPED.load(Ordering::SeqCst) == 10 {
if DROPPED.load(Ordering::SeqCst) == 11 {
return;
}

Expand Down Expand Up @@ -626,7 +626,7 @@ async fn test_conn_fail_once() {

async fn connect(&self) -> Result<Self::Connection, Self::Error> {
// only fail once so the retry should work
if FAILED_ONCE.load(Ordering::SeqCst) {
if FAILED_ONCE.load(Ordering::SeqCst) || NB_CALL.load(Ordering::SeqCst) == 0 {
Ok(Connection)
} else {
FAILED_ONCE.store(true, Ordering::SeqCst);
Expand Down