From aea5510c89272d66fc74dd273188f96af1241a33 Mon Sep 17 00:00:00 2001 From: hamz2a Date: Fri, 5 Jul 2024 16:01:45 +0200 Subject: [PATCH] editoast: add Deadlocks comment --- editoast/editoast_models/src/db_connection_pool.rs | 8 ++++++++ editoast/src/generated_data/mod.rs | 5 ++++- editoast/src/modelsv2/infra.rs | 2 ++ editoast/src/views/infra/mod.rs | 5 ++++- editoast/src/views/infra/railjson.rs | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/editoast/editoast_models/src/db_connection_pool.rs b/editoast/editoast_models/src/db_connection_pool.rs index 9bc32b66d51..55e2eb1acaf 100644 --- a/editoast/editoast_models/src/db_connection_pool.rs +++ b/editoast/editoast_models/src/db_connection_pool.rs @@ -134,6 +134,14 @@ impl DbConnectionPoolV2 { /// # } /// ``` /// + /// ### Deadlocks + /// + /// We encountered a deadlock error in our tests, + /// especially those using `empty_infra` and `small_infra`. + /// Adding `#[serial_test::serial]` solved the issue. + /// We tried increasing the deadlock timeout, but that didn't work. + /// Using random `infra_id` with rand didn't help either. + /// /// ## Guidelines /// /// To prevent these issues, prefer the following patterns: diff --git a/editoast/src/generated_data/mod.rs b/editoast/src/generated_data/mod.rs index 181e113e3bf..d4f51e6a02d 100644 --- a/editoast/src/generated_data/mod.rs +++ b/editoast/src/generated_data/mod.rs @@ -172,7 +172,10 @@ pub mod tests { use crate::modelsv2::fixtures::create_empty_infra; use editoast_models::DbConnectionPoolV2; - #[rstest] // Slow test + #[rstest] + // Slow test + // PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information + #[serial_test::serial] async fn refresh_all_test() { let db_pool = DbConnectionPoolV2::for_tests(); let infra = create_empty_infra(db_pool.get_ok().deref_mut()).await; diff --git a/editoast/src/modelsv2/infra.rs b/editoast/src/modelsv2/infra.rs index 3c402bd847d..c96726831a5 100644 --- a/editoast/src/modelsv2/infra.rs +++ b/editoast/src/modelsv2/infra.rs @@ -333,6 +333,8 @@ pub mod tests { } #[rstest] + // PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information + #[serial_test::serial] async fn clone_infra_with_new_name_returns_new_cloned_infra() { // GIVEN let db_pool = DbConnectionPoolV2::for_tests(); diff --git a/editoast/src/views/infra/mod.rs b/editoast/src/views/infra/mod.rs index 493d72ebe87..52ff99ba3af 100644 --- a/editoast/src/views/infra/mod.rs +++ b/editoast/src/views/infra/mod.rs @@ -884,7 +884,10 @@ pub mod tests { assert_eq!(refreshed_infras.infra_refreshed, vec![empty_infra.id]); } - #[rstest] // Slow test + #[rstest] + // Slow test + // PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information + #[serial_test::serial] async fn infra_refresh_force() { let app = TestAppBuilder::default_app(); let db_pool = app.db_pool(); diff --git a/editoast/src/views/infra/railjson.rs b/editoast/src/views/infra/railjson.rs index 7a474fa6fc8..d5f2edd6718 100644 --- a/editoast/src/views/infra/railjson.rs +++ b/editoast/src/views/infra/railjson.rs @@ -196,6 +196,7 @@ mod tests { use editoast_schemas::infra::SwitchType; #[rstest] + // PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information #[serial_test::serial] async fn test_get_railjson() { let app = TestAppBuilder::default_app(); @@ -221,6 +222,7 @@ mod tests { } #[rstest] + // PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information #[serial_test::serial] async fn test_post_railjson() { let app = TestAppBuilder::default_app();