From 2677046a3b5f45d781722815e0ebc46b0824fb6f Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Mon, 8 Jun 2020 11:34:49 +0200 Subject: [PATCH] test: add test case for fetch_all bug with pool --- tests/mysql/mysql.rs | 50 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/mysql/mysql.rs b/tests/mysql/mysql.rs index dfe84ce3..b95dae28 100644 --- a/tests/mysql/mysql.rs +++ b/tests/mysql/mysql.rs @@ -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 = sqlx::query_as::( + "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::().await?;