From 7a2d913458685bbcc84eca60e7bbe31dab4f1b5c Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 17 Oct 2026 23:23:53 +0200 Subject: [PATCH] perf: opt into sqlx test templates through SQLX_TEST_TEMPLATE (#11853) * perf: opt into sqlx test templates through SQLX_TEST_TEMPLATE Co-Authored-By: Claude Opus 5.5 * fix: raise the sqlx test connection cap so concurrent tests cannot starve Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- backend/.cargo/config.toml | 5 ++++- backend/Cargo.lock | 14 +++++++------- backend/Cargo.toml | 24 ++++++++++++------------ 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/backend/.cargo/config.toml b/backend/.cargo/config.toml index 9284b39837..2b90b4bb23 100644 --- a/backend/.cargo/config.toml +++ b/backend/.cargo/config.toml @@ -27,8 +27,11 @@ rustflags = [ git-fetch-with-cli = true [env] +# `#[sqlx::test]` clones each test database from a template migrated once, instead of running +# every migration per test. The `_sqlx_tmpl_*` databases it leaves on the server are reused. +SQLX_TEST_TEMPLATE = "true" # All `#[sqlx::test]` pools of a test binary share this many connections, and each keeps the # ones it took until it ends: below 5 per test thread, concurrent tests can split them all and # wait on each other until their acquire times out. 50 covers CI's `--test-threads=10`; a run # with more threads over a binary of more than 10 tests needs 5 per thread. -SQLX_TEST_MAX_CONNECTIONS = "50" \ No newline at end of file +SQLX_TEST_MAX_CONNECTIONS = "50" diff --git a/backend/Cargo.lock b/backend/Cargo.lock index e442dbc533..7170d22fe1 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -12610,7 +12610,7 @@ dependencies = [ [[package]] name = "sqlx" version = "0.8.6" -source = "git+https://github.com/windmill-labs/sqlx?rev=cb0d1c3d481f993b763806c0d96e63e53b870a70#cb0d1c3d481f993b763806c0d96e63e53b870a70" +source = "git+https://github.com/windmill-labs/sqlx?rev=c1c5f1f2a07cb1fce0e47463c314697e08f4f26b#c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" dependencies = [ "sqlx-core", "sqlx-macros", @@ -12622,7 +12622,7 @@ dependencies = [ [[package]] name = "sqlx-core" version = "0.8.6" -source = "git+https://github.com/windmill-labs/sqlx?rev=cb0d1c3d481f993b763806c0d96e63e53b870a70#cb0d1c3d481f993b763806c0d96e63e53b870a70" +source = "git+https://github.com/windmill-labs/sqlx?rev=c1c5f1f2a07cb1fce0e47463c314697e08f4f26b#c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" dependencies = [ "base64 0.22.1", "bigdecimal", @@ -12660,7 +12660,7 @@ dependencies = [ [[package]] name = "sqlx-macros" version = "0.8.6" -source = "git+https://github.com/windmill-labs/sqlx?rev=cb0d1c3d481f993b763806c0d96e63e53b870a70#cb0d1c3d481f993b763806c0d96e63e53b870a70" +source = "git+https://github.com/windmill-labs/sqlx?rev=c1c5f1f2a07cb1fce0e47463c314697e08f4f26b#c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" dependencies = [ "proc-macro2", "quote", @@ -12672,7 +12672,7 @@ dependencies = [ [[package]] name = "sqlx-macros-core" version = "0.8.6" -source = "git+https://github.com/windmill-labs/sqlx?rev=cb0d1c3d481f993b763806c0d96e63e53b870a70#cb0d1c3d481f993b763806c0d96e63e53b870a70" +source = "git+https://github.com/windmill-labs/sqlx?rev=c1c5f1f2a07cb1fce0e47463c314697e08f4f26b#c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" dependencies = [ "dotenvy", "either", @@ -12696,7 +12696,7 @@ dependencies = [ [[package]] name = "sqlx-mysql" version = "0.8.6" -source = "git+https://github.com/windmill-labs/sqlx?rev=cb0d1c3d481f993b763806c0d96e63e53b870a70#cb0d1c3d481f993b763806c0d96e63e53b870a70" +source = "git+https://github.com/windmill-labs/sqlx?rev=c1c5f1f2a07cb1fce0e47463c314697e08f4f26b#c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" dependencies = [ "atoi", "base64 0.22.1", @@ -12740,7 +12740,7 @@ dependencies = [ [[package]] name = "sqlx-postgres" version = "0.8.6" -source = "git+https://github.com/windmill-labs/sqlx?rev=cb0d1c3d481f993b763806c0d96e63e53b870a70#cb0d1c3d481f993b763806c0d96e63e53b870a70" +source = "git+https://github.com/windmill-labs/sqlx?rev=c1c5f1f2a07cb1fce0e47463c314697e08f4f26b#c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" dependencies = [ "atoi", "base64 0.22.1", @@ -12780,7 +12780,7 @@ dependencies = [ [[package]] name = "sqlx-sqlite" version = "0.8.6" -source = "git+https://github.com/windmill-labs/sqlx?rev=cb0d1c3d481f993b763806c0d96e63e53b870a70#cb0d1c3d481f993b763806c0d96e63e53b870a70" +source = "git+https://github.com/windmill-labs/sqlx?rev=c1c5f1f2a07cb1fce0e47463c314697e08f4f26b#c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" dependencies = [ "atoi", "chrono", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 48fa9c2460..1f4ed3acc4 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -226,11 +226,11 @@ all_sqlx_features = ["all_languages", "enterprise", "enterprise_saml", "embeddin "windmill-git-sync/all_sqlx_features"] [patch.crates-io] -# v0.8.6 plus the fix below and two `#[sqlx::test]`-only changes: each test database is -# cloned from a template migrated once per migration set instead of migrating it per test, and -# `SQLX_TEST_MAX_CONNECTIONS` (set in .cargo/config.toml) lifts the cap on the connections all -# test pools share. The rev is tagged `windmill-0.8.6-test-pool-cap-cb0d1c3` in the fork so it -# stays fetchable. +# v0.8.6 plus the fix below and two `#[sqlx::test]`-only changes, both set in .cargo/config.toml: +# `SQLX_TEST_TEMPLATE` clones each test database from a template migrated once per migration +# set instead of migrating it per test, and `SQLX_TEST_MAX_CONNECTIONS` lifts the cap on the +# connections all test pools share. The rev is tagged `windmill-0.8.6-test-template-c1c5f1f` in +# the fork so it stays fetchable. # The fix: `Pool::begin` is not cancel-safe on Postgres. sqlx raises the # transaction depth its rollback-on-drop guard keys on only *after* the BEGIN round trip, so # a cancelled caller (a disconnecting API client, a `timeout`, an aborted task) leaves the @@ -244,13 +244,13 @@ all_sqlx_features = ["all_languages", "enterprise", "enterprise_saml", "embeddin # Changing any of this — a bump, a rebase of the fork, dropping these lines — still compiles # clean, so run the guard that actually checks the behaviour is still there: # cargo test -p windmill-common --test sqlx_begin_cancel_safe -- --ignored -sqlx = { git = "https://github.com/windmill-labs/sqlx", rev = "cb0d1c3d481f993b763806c0d96e63e53b870a70" } -sqlx-core = { git = "https://github.com/windmill-labs/sqlx", rev = "cb0d1c3d481f993b763806c0d96e63e53b870a70" } -sqlx-macros = { git = "https://github.com/windmill-labs/sqlx", rev = "cb0d1c3d481f993b763806c0d96e63e53b870a70" } -sqlx-macros-core = { git = "https://github.com/windmill-labs/sqlx", rev = "cb0d1c3d481f993b763806c0d96e63e53b870a70" } -sqlx-postgres = { git = "https://github.com/windmill-labs/sqlx", rev = "cb0d1c3d481f993b763806c0d96e63e53b870a70" } -sqlx-mysql = { git = "https://github.com/windmill-labs/sqlx", rev = "cb0d1c3d481f993b763806c0d96e63e53b870a70" } -sqlx-sqlite = { git = "https://github.com/windmill-labs/sqlx", rev = "cb0d1c3d481f993b763806c0d96e63e53b870a70" } +sqlx = { git = "https://github.com/windmill-labs/sqlx", rev = "c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" } +sqlx-core = { git = "https://github.com/windmill-labs/sqlx", rev = "c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" } +sqlx-macros = { git = "https://github.com/windmill-labs/sqlx", rev = "c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" } +sqlx-macros-core = { git = "https://github.com/windmill-labs/sqlx", rev = "c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" } +sqlx-postgres = { git = "https://github.com/windmill-labs/sqlx", rev = "c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" } +sqlx-mysql = { git = "https://github.com/windmill-labs/sqlx", rev = "c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" } +sqlx-sqlite = { git = "https://github.com/windmill-labs/sqlx", rev = "c1c5f1f2a07cb1fce0e47463c314697e08f4f26b" } object_store = { git = "https://github.com/apache/arrow-rs-object-store", rev = "36752c975d4f29e20b57c91f81a10872dcd48ae7" } # Use tiberius main branch for libgssapi 0.8.1 fix (https://github.com/prisma/tiberius/issues/343) tiberius = { git = "https://github.com/prisma/tiberius", rev = "59db57960a14b422fb3a1309aa4aa47880896ff8" }