Skip to content

Commit ef3ef96

Browse files
committed
editoast: add Deadlocks comment
1 parent b3bd952 commit ef3ef96

File tree

9 files changed

+20
-17
lines changed

9 files changed

+20
-17
lines changed

editoast/editoast_models/src/db_connection_pool.rs

+8
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ impl DbConnectionPoolV2 {
134134
/// # }
135135
/// ```
136136
///
137+
/// ### Deadlocks
138+
///
139+
/// We encountered a deadlock error in our tests,
140+
/// especially those using `empty_infra` and `small_infra`.
141+
/// Adding `#[serial_test::serial]` solved the issue.
142+
/// We tried increasing the deadlock timeout, but that didn't work.
143+
/// Using random `infra_id` with rand didn't help either.
144+
///
137145
/// ## Guidelines
138146
///
139147
/// To prevent these issues, prefer the following patterns:

editoast/src/generated_data/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use crate::error::Result;
4040
use crate::infra_cache::operation::CacheOperation;
4141
use crate::infra_cache::InfraCache;
4242
use editoast_models::DbConnection;
43-
use editoast_models::DbConnectionPool;
4443
use editoast_models::DbConnectionPoolV2;
4544

4645
editoast_common::schemas! {
@@ -173,7 +172,9 @@ pub mod tests {
173172
use crate::modelsv2::fixtures::create_empty_infra;
174173
use editoast_models::DbConnectionPoolV2;
175174

176-
#[rstest] // Slow test
175+
#[rstest]
176+
// Slow test
177+
// PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information
177178
#[serial_test::serial]
178179
async fn refresh_all_test() {
179180
let db_pool = DbConnectionPoolV2::for_tests();

editoast/src/modelsv2/infra.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ use crate::modelsv2::get_table;
3737
use crate::modelsv2::prelude::*;
3838
use crate::modelsv2::railjson::persist_railjson;
3939
use crate::modelsv2::Create;
40-
use crate::modelsv2::DbConnection;
41-
use crate::modelsv2::DbConnectionPoolV2;
4240
use crate::tables::infra::dsl;
4341
use editoast_models::DbConnection;
44-
use editoast_models::DbConnectionPool;
4542
use editoast_models::DbConnectionPoolV2;
4643
use editoast_schemas::infra::RailJson;
4744
use editoast_schemas::infra::RAILJSON_VERSION;
@@ -337,6 +334,7 @@ pub mod tests {
337334
}
338335

339336
#[rstest]
337+
// PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information
340338
#[serial_test::serial]
341339
async fn clone_infra_with_new_name_returns_new_cloned_infra() {
342340
// GIVEN

editoast/src/modelsv2/railjson.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ use editoast_schemas::infra::RAILJSON_VERSION;
55
use crate::error::Result;
66
use crate::modelsv2::infra_objects::*;
77
use crate::modelsv2::prelude::*;
8-
use editoast_models::DbConnection;
9-
use editoast_models::DbConnectionPool;
10-
use editoast_models::DbConnectionPoolV2;
118
use diesel_async::AsyncConnection;
9+
use editoast_models::DbConnection;
1210

1311
#[derive(Debug, thiserror::Error, EditoastError)]
1412
#[editoast_error(base_id = "railjson")]

editoast/src/views/infra/auto_fixes/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ use crate::modelsv2::prelude::*;
2828
use crate::modelsv2::Infra;
2929
use crate::views::infra::InfraApiError;
3030
use crate::views::infra::InfraIdParam;
31-
use editoast_models::DbConnection;
32-
use editoast_models::DbConnectionPool;
3331
use editoast_models::DbConnectionPoolV2;
3432
use editoast_schemas::infra::InfraObject;
3533
use editoast_schemas::primitives::OSRDIdentified as _;

editoast/src/views/infra/edition.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use crate::views::infra::InfraApiError;
4343
use crate::views::infra::InfraIdParam;
4444
use crate::RedisClient;
4545
use editoast_models::DbConnection;
46-
use editoast_models::DbConnectionPool;
4746
use editoast_models::DbConnectionPoolV2;
4847
use editoast_schemas::infra::InfraObject;
4948

@@ -158,7 +157,7 @@ pub async fn split_track_section<'a>(
158157

159158
// Calling the DB to get the full object and also the split geo
160159
let result = infra
161-
.get_splited_track_section_with_data(
160+
.get_split_track_section_with_data(
162161
db_pool.get().await?.deref_mut(),
163162
payload.track.clone(),
164163
distance_fraction,

editoast/src/views/infra/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use crate::modelsv2::Infra;
4646
use crate::views::pagination::PaginatedList as _;
4747
use crate::views::pagination::PaginationQueryParam;
4848
use crate::RedisClient;
49-
use editoast_models::DbConnectionPool;
5049
use editoast_models::DbConnectionPoolV2;
5150
use editoast_schemas::infra::SwitchType;
5251

@@ -885,7 +884,10 @@ pub mod tests {
885884
assert_eq!(refreshed_infras.infra_refreshed, vec![empty_infra.id]);
886885
}
887886

888-
#[rstest] // Slow test
887+
#[rstest]
888+
// Slow test
889+
// PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information
890+
#[serial_test::serial]
889891
async fn infra_refresh_force() {
890892
let app = TestAppBuilder::default_app();
891893
let db_pool = app.db_pool();

editoast/src/views/infra/railjson.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use crate::modelsv2::prelude::*;
2727
use crate::modelsv2::Infra;
2828
use crate::views::infra::InfraApiError;
2929
use crate::views::infra::InfraIdParam;
30-
use editoast_models::DbConnection;
31-
use editoast_models::DbConnectionPool;
3230
use editoast_models::DbConnectionPoolV2;
3331
use editoast_schemas::primitives::ObjectType;
3432

@@ -198,6 +196,7 @@ mod tests {
198196
use editoast_schemas::infra::SwitchType;
199197

200198
#[rstest]
199+
// PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information
201200
#[serial_test::serial]
202201
async fn test_get_railjson() {
203202
let app = TestAppBuilder::default_app();
@@ -223,6 +222,7 @@ mod tests {
223222
}
224223

225224
#[rstest]
225+
// PostgreSQL deadlock can happen in this test, see section `Deadlock` of [DbConnectionPoolV2::get] for more information
226226
#[serial_test::serial]
227227
async fn test_post_railjson() {
228228
let app = TestAppBuilder::default_app();

editoast/src/views/infra/routes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::modelsv2::Infra;
2222
use crate::views::infra::InfraApiError;
2323
use crate::views::infra::InfraIdParam;
2424
use crate::views::params::List;
25-
use editoast_models::DbConnectionPool;
2625
use editoast_models::DbConnectionPoolV2;
2726

2827
crate::routes! {

0 commit comments

Comments
 (0)