mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
test: add test case for fetch_all bug with pool
This commit is contained in:
parent
e54d030381
commit
2677046a3b
1 changed files with 49 additions and 1 deletions
|
@ -1,7 +1,8 @@
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use sqlx::mysql::{MySql, MySqlRow};
|
use sqlx::mysql::{MySql, MySqlRow, MySqlPool};
|
||||||
use sqlx::{Connection, Executor, Row};
|
use sqlx::{Connection, Executor, Row};
|
||||||
use sqlx_test::new;
|
use sqlx_test::new;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
#[sqlx_macros::test]
|
#[sqlx_macros::test]
|
||||||
async fn it_connects() -> anyhow::Result<()> {
|
async fn it_connects() -> anyhow::Result<()> {
|
||||||
|
@ -74,6 +75,53 @@ CREATE TEMPORARY TABLE users (id INTEGER PRIMARY KEY);
|
||||||
Ok(())
|
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]
|
#[sqlx_macros::test]
|
||||||
async fn it_drops_results_in_affected_rows() -> anyhow::Result<()> {
|
async fn it_drops_results_in_affected_rows() -> anyhow::Result<()> {
|
||||||
let mut conn = new::<MySql>().await?;
|
let mut conn = new::<MySql>().await?;
|
||||||
|
|
Loading…
Reference in a new issue