Skip to content

Commit

Permalink
Restore ManageConnection::is_valid original signature
Browse files Browse the repository at this point in the history
  • Loading branch information
arnodb authored and djc committed Nov 24, 2021
1 parent 58ff9b0 commit eb5c1a9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bb8/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub trait ManageConnection: Sized + Send + Sync + 'static {
/// Attempts to create a new connection.
async fn connect(&self) -> Result<Self::Connection, Self::Error>;
/// Determines if the connection is still connected to the database.
async fn is_valid(&self, conn: &mut PooledConnection<'_, Self>) -> Result<(), Self::Error>;
async fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error>;
/// Synchronously determine if the connection is no longer usable, if possible.
fn has_broken(&self, conn: &mut Self::Connection) -> bool;
}
Expand Down
29 changes: 7 additions & 22 deletions bb8/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
Ok(Default::default())
}

async fn is_valid(&self, _conn: &mut PooledConnection<'_, Self>) -> Result<(), Self::Error> {
async fn is_valid(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
Ok(())
}

Expand Down Expand Up @@ -97,7 +97,7 @@ where
}
}

async fn is_valid(&self, _conn: &mut PooledConnection<'_, Self>) -> Result<(), Self::Error> {
async fn is_valid(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
Ok(())
}

Expand Down Expand Up @@ -233,10 +233,7 @@ async fn test_drop_on_broken() {
Ok(Default::default())
}

async fn is_valid(
&self,
_conn: &mut PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
async fn is_valid(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
Ok(())
}

Expand Down Expand Up @@ -327,10 +324,7 @@ async fn test_now_invalid() {
}
}

async fn is_valid(
&self,
_conn: &mut PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
async fn is_valid(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
println!("Called is_valid");
if INVALID.load(Ordering::SeqCst) {
println!("Not");
Expand Down Expand Up @@ -536,10 +530,7 @@ async fn test_conns_drop_on_pool_drop() {
Ok(Connection)
}

async fn is_valid(
&self,
_conn: &mut PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
async fn is_valid(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
Ok(())
}

Expand Down Expand Up @@ -591,10 +582,7 @@ async fn test_retry() {
Ok(Connection)
}

async fn is_valid(
&self,
_conn: &mut PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
async fn is_valid(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
// only fail once so the retry should work
if FAILED_ONCE.load(Ordering::SeqCst) {
Ok(())
Expand Down Expand Up @@ -646,10 +634,7 @@ async fn test_conn_fail_once() {
}
}

async fn is_valid(
&self,
_conn: &mut PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
async fn is_valid(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
Ok(())
}

Expand Down
5 changes: 1 addition & 4 deletions postgres/examples/custom_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ where
Ok(CustomPostgresConnection::new(conn))
}

async fn is_valid(
&self,
conn: &mut bb8::PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
async fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
conn.simple_query("").await.map(|_| ())
}

Expand Down
5 changes: 1 addition & 4 deletions postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ where
Ok(client)
}

async fn is_valid(
&self,
conn: &mut bb8::PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
async fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
conn.simple_query("").await.map(|_| ())
}

Expand Down
9 changes: 2 additions & 7 deletions redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#![allow(clippy::needless_doctest_main)]
#![deny(missing_docs, missing_debug_implementations)]

use std::ops::DerefMut;

pub use bb8;
pub use redis;

Expand Down Expand Up @@ -69,11 +67,8 @@ impl bb8::ManageConnection for RedisConnectionManager {
self.client.get_async_connection().await
}

async fn is_valid(
&self,
conn: &mut bb8::PooledConnection<'_, Self>,
) -> Result<(), Self::Error> {
let pong: String = redis::cmd("PING").query_async(conn.deref_mut()).await?;
async fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
let pong: String = redis::cmd("PING").query_async(conn).await?;
match pong.as_str() {
"PONG" => Ok(()),
_ => Err((ErrorKind::ResponseError, "ping request").into()),
Expand Down

0 comments on commit eb5c1a9

Please sign in to comment.