Skip to content

Commit

Permalink
rename test_is_valid_once, fix and clean it
Browse files Browse the repository at this point in the history
  • Loading branch information
bbigras authored and khuey committed Nov 24, 2019
1 parent 19a87cb commit 8bf965c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,12 @@ fn test_conns_drop_on_pool_drop() {
);
}

// make sure that bb8 retries after is_valid fails once
#[test]
fn test_is_valid_once() {
struct Connection {
once: bool,
};
fn test_retry() {
static FAILED_ONCE: AtomicBool = AtomicBool::new(false);

struct Connection;
struct Handler;

#[async_trait]
Expand All @@ -674,18 +675,19 @@ fn test_is_valid_once() {
type Error = Error;

async fn connect(&self) -> Result<Self::Connection, Self::Error> {
Ok(Connection { once: false })
Ok(Connection)
}

async fn is_valid(
&self,
mut conn: Self::Connection,
conn: Self::Connection,
) -> Result<Self::Connection, (Self::Error, Self::Connection)> {
if !conn.once {
conn.once = true;
Err((Error, conn))
} else {
// only fail once so the retry should work
if FAILED_ONCE.load(Ordering::SeqCst) {
Ok(conn)
} else {
FAILED_ONCE.store(true, Ordering::SeqCst);
Err((Error, conn))
}
}

Expand All @@ -700,7 +702,8 @@ fn test_is_valid_once() {
.block_on(async { Pool::builder().max_size(1).build(Handler).await })
.unwrap();

for _i in 0..2 {
// is_valid() will be called between the 2 iterations
for _ in 0..2 {
event_loop.block_on(async {
pool.run(|c: Connection| {
async { Ok::<((), Connection), (Error, Connection)>(((), c)) }
Expand Down

0 comments on commit 8bf965c

Please sign in to comment.