File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,6 +41,38 @@ This feature is activated by changing the signature of your test function. The f
4141
4242Where ` DB ` is a supported ` Database ` type and ` Ret ` is ` () ` or ` Result<_, _> ` .
4343
44+ ##### Concurrent Tests and Connection Limits
45+
46+ Each ` #[sqlx::test] ` gets its own database and pool, but all tests in the same process still share the
47+ database server's connection limit. If many tests run in parallel and fail with ` PoolTimedOut ` , reduce
48+ the test runner's concurrency, increase the server's connection limit, or reduce the per-test pool size.
49+
50+ To reduce the per-test pool size, use the ` PoolOptions ` signature and create the pool explicitly:
51+
52+ ``` rust,no_run
53+ # #[cfg(all(feature = "migrate", feature = "postgres"))]
54+ # mod example {
55+ use sqlx::{pool::PoolOptions, postgres::PgConnectOptions, Postgres};
56+
57+ #[sqlx::test]
58+ async fn basic_test(
59+ pool_options: PoolOptions<Postgres>,
60+ connect_options: PgConnectOptions,
61+ ) -> sqlx::Result<()> {
62+ let pool = pool_options
63+ .max_connections(1)
64+ .connect_with(connect_options)
65+ .await?;
66+
67+ sqlx::query("SELECT 1").execute(&pool).await?;
68+
69+ Ok(())
70+ }
71+ # }
72+ ```
73+
74+ You can also limit Rust's built-in test runner with ` cargo test -- --test-threads <N> ` .
75+
4476##### Supported Databases
4577
4678Most of these will require you to set ` DATABASE_URL ` as an environment variable
You can’t perform that action at this time.
0 commit comments