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