Skip to content

Commit

Permalink
Merge pull request djc#1 from bbigras/test_is_valid_once
Browse files Browse the repository at this point in the history
test_is_valid_once()
  • Loading branch information
djc committed Nov 9, 2019
2 parents dd18811 + 6d02886 commit 0a44ace
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,53 @@ fn test_conns_drop_on_pool_drop() {
DROPPED.load(Ordering::SeqCst)
);
}

#[test]
fn test_is_valid_once() {
struct Connection {
once: bool,
};
struct Handler;

#[async_trait]
impl ManageConnection for Handler {
type Connection = Connection;
type Error = Error;

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

async fn is_valid(
&self,
mut conn: Self::Connection,
) -> Result<Self::Connection, (Self::Error, Self::Connection)> {
if !conn.once {
conn.once = true;
Err((Error, conn))
} else {
Ok(conn)
}
}

fn has_broken(&self, _: &mut Self::Connection) -> bool {
false
}
}

let mut event_loop = Runtime::new().unwrap();

let pool = event_loop
.block_on(async { Pool::builder().max_size(1).build(Handler).await })
.unwrap();

for _i in 0..2 {
event_loop.block_on(async {
pool.run(|c: Connection| {
async { Ok::<((), Connection), (Error, Connection)>(((), c)) }
})
.await
.unwrap();
});
}
}

0 comments on commit 0a44ace

Please sign in to comment.