mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
test: more pool usage adjustments
This commit is contained in:
parent
fc682fa991
commit
93cab2a197
8 changed files with 30 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
|||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
fn bench_pgpool_acquire(c: &mut Criterion) {
|
||||
|
@ -23,7 +24,9 @@ fn bench_pgpool_acquire(c: &mut Criterion) {
|
|||
|
||||
fn do_bench_acquire(b: &mut Bencher, concurrent: u32, fair: bool) {
|
||||
let pool = sqlx_rt::block_on(
|
||||
PgPool::builder()
|
||||
PgPoolOptions::new(
|
||||
&dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set to run benchmarks"),
|
||||
)
|
||||
// we don't want timeouts because we want to see how the pool degrades
|
||||
.connect_timeout(Duration::from_secs(3600))
|
||||
// force the pool to start full
|
||||
|
@ -32,9 +35,7 @@ fn do_bench_acquire(b: &mut Bencher, concurrent: u32, fair: bool) {
|
|||
// we're not benchmarking `ping()`
|
||||
.test_before_acquire(false)
|
||||
.__fair(fair)
|
||||
.build(
|
||||
&dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set to run benchmarks"),
|
||||
),
|
||||
.connect(),
|
||||
)
|
||||
.expect("failed to open PgPool");
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@ pub use value::{MySqlValue, MySqlValueFormat, MySqlValueRef};
|
|||
/// An alias for [`Pool`][crate::pool::Pool], specialized for MySQL.
|
||||
pub type MySqlPool = crate::pool::Pool<MySql>;
|
||||
|
||||
/// An alias for [`PoolOptions`][crate::pool::PoolOptions], specialized for MySQL.
|
||||
pub type MySqlPoolOptions = crate::pool::PoolOptions<MySql>;
|
||||
|
||||
// NOTE: required due to the lack of lazy normalization
|
||||
impl_into_arguments_for_arguments!(MySqlArguments);
|
||||
impl_executor_for_pool_connection!(MySql, MySqlConnection, MySqlRow);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
pub use sqlx_core::acquire::Acquire;
|
||||
pub use sqlx_core::arguments::{Arguments, IntoArguments};
|
||||
pub use sqlx_core::column::Column;
|
||||
pub use sqlx_core::connection::Connection;
|
||||
pub use sqlx_core::connection::{ConnectOptions, Connection};
|
||||
pub use sqlx_core::database::{self, Database};
|
||||
pub use sqlx_core::executor::{Execute, Executor};
|
||||
pub use sqlx_core::from_row::FromRow;
|
||||
|
@ -124,6 +124,7 @@ pub mod query {
|
|||
/// Convenience re-export of common traits.
|
||||
pub mod prelude {
|
||||
pub use super::Acquire;
|
||||
pub use super::ConnectOptions;
|
||||
pub use super::Connection;
|
||||
pub use super::Executor;
|
||||
pub use super::FromRow;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use futures::TryStreamExt;
|
||||
use sqlx::mssql::Mssql;
|
||||
use sqlx::{Connect, Connection, Executor, MssqlConnection, Row};
|
||||
use sqlx::{Connection, Executor, MssqlConnection, Row};
|
||||
use sqlx_core::mssql::MssqlRow;
|
||||
use sqlx_test::new;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use futures::TryStreamExt;
|
||||
use sqlx::mysql::{MySql, MySqlPool, MySqlRow};
|
||||
use sqlx::mysql::{MySql, MySqlPool, MySqlPoolOptions, MySqlRow};
|
||||
use sqlx::{Connection, Executor, Row};
|
||||
use sqlx_test::new;
|
||||
|
||||
|
@ -73,13 +73,14 @@ CREATE TEMPORARY TABLE users (id INTEGER PRIMARY KEY);
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_executes_with_pool() -> anyhow::Result<()> {
|
||||
let pool: MySqlPool = MySqlPool::builder()
|
||||
let pool: MySqlPool = MySqlPoolOptions::new(&dotenv::var("DATABASE_URL")?)?
|
||||
.min_connections(2)
|
||||
.max_connections(2)
|
||||
.test_before_acquire(false)
|
||||
.build(&dotenv::var("DATABASE_URL")?)
|
||||
.connect()
|
||||
.await?;
|
||||
|
||||
let rows = pool.fetch_all("SELECT 1; SELECT 2").await?;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use sqlx::error::DatabaseError;
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqliteError};
|
||||
use sqlx::ConnectOptions;
|
||||
use sqlx::{sqlite::Sqlite, Column, Executor};
|
||||
use sqlx::{Connect, SqliteConnection, TypeInfo};
|
||||
use sqlx::{SqliteConnection, TypeInfo};
|
||||
use sqlx_test::new;
|
||||
use std::env;
|
||||
|
||||
|
@ -159,7 +160,7 @@ async fn it_describes_insert_with_read_only() -> anyhow::Result<()> {
|
|||
let mut options: SqliteConnectOptions = env::var("DATABASE_URL")?.parse().unwrap();
|
||||
options = options.read_only(true);
|
||||
|
||||
let mut conn = SqliteConnection::connect_with(&options).await?;
|
||||
let mut conn = options.connect().await?;
|
||||
|
||||
let d = conn
|
||||
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello')")
|
||||
|
|
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
use futures::TryStreamExt;
|
||||
use sqlx::sqlite::SqlitePoolOptions;
|
||||
use sqlx::{
|
||||
query, sqlite::Sqlite, sqlite::SqliteRow, Connect, Connection, Executor, Row, SqliteConnection,
|
||||
query, sqlite::Sqlite, sqlite::SqliteRow, Connection, Executor, Row, SqliteConnection,
|
||||
SqlitePool,
|
||||
};
|
||||
use sqlx_test::new;
|
||||
|
@ -126,11 +127,11 @@ async fn it_fetches_in_loop() -> anyhow::Result<()> {
|
|||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_executes_with_pool() -> anyhow::Result<()> {
|
||||
let pool: SqlitePool = SqlitePool::builder()
|
||||
let pool: SqlitePool = SqlitePoolOptions::new(&dotenv::var("DATABASE_URL")?)?
|
||||
.min_connections(2)
|
||||
.max_connections(2)
|
||||
.test_before_acquire(false)
|
||||
.build(&dotenv::var("DATABASE_URL")?)
|
||||
.connect()
|
||||
.await?;
|
||||
|
||||
let rows = pool.fetch_all("SELECT 1; SElECT 2").await?;
|
||||
|
|
Loading…
Reference in a new issue