test: add test case for fetch_all bug with pool

This commit is contained in:
Peter Maatman 2020-06-08 11:34:49 +02:00 committed by Ryan Leckey
parent e54d030381
commit 2677046a3b

View file

@ -1,7 +1,8 @@
use futures::TryStreamExt;
use sqlx::mysql::{MySql, MySqlRow};
use sqlx::mysql::{MySql, MySqlRow, MySqlPool};
use sqlx::{Connection, Executor, Row};
use sqlx_test::new;
use std::env;
#[sqlx_macros::test]
async fn it_connects() -> anyhow::Result<()> {
@ -74,6 +75,53 @@ CREATE TEMPORARY TABLE users (id INTEGER PRIMARY KEY);
Ok(())
}
#[sqlx_macros::test]
async fn it_executes_2() -> anyhow::Result<()> {
let pool: MySqlPool = MySqlPool::builder()
.max_size(2)
.build(&env::var("DATABASE_URL")?)
.await?;
let mut conn = pool.acquire().await?;
#[derive(Debug, sqlx::FromRow)]
struct User { id: i32 };
let _ = sqlx::query(
r#"
CREATE TABLE users (id INTEGER PRIMARY KEY);
"#,
)
.execute(&mut conn)
.await?;
for index in 1..=10_i32 {
let cnt = sqlx::query("INSERT INTO users (id) VALUES (?)")
.bind(index)
.execute(&mut conn)
.await?;
assert_eq!(cnt, 1);
}
let users: Vec<User> = sqlx::query_as::<MySql, User>(
"SELECT
id
FROM
users"
)
.fetch_all(&pool)
.await?;
assert_eq!(users.len(), 10);
sqlx::query("drop table users;").execute(&mut conn).await?;
Ok(())
}
#[sqlx_macros::test]
async fn it_drops_results_in_affected_rows() -> anyhow::Result<()> {
let mut conn = new::<MySql>().await?;