From 5983cc0319eb415314c38a0440b4d4ec9621258a Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sat, 2 Nov 2024 00:38:21 +0100 Subject: [PATCH] added fixes for bugs which the new testcase revealed --- server/src/locations/details.rs | 25 ++++++++----------------- server/src/setup/tests.rs | 26 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/server/src/locations/details.rs b/server/src/locations/details.rs index 5b1f9cff1..a670c4a94 100644 --- a/server/src/locations/details.rs +++ b/server/src/locations/details.rs @@ -239,6 +239,7 @@ struct OverlayMapEntry { } #[derive(Deserialize, Serialize, Debug, Default)] +#[serde(rename_all = "snake_case")] enum DefaultMaps { #[default] Interactive, @@ -369,15 +370,15 @@ struct Coordinate { #[serde(rename_all = "snake_case")] enum CoordinateAccuracy { #[default] - Buiding, + Building, } #[derive(Serialize, Deserialize, Debug, Default)] #[serde(rename_all = "snake_case")] enum CoordinateSource { - Roomfinder, #[default] Navigatum, + Roomfinder, Inferred, } @@ -438,36 +439,26 @@ mod tests { use super::*; use crate::{setup::tests::PostgresTestContainer, AppData}; - /// Allows tesing if a modification has changed the output of the details API + /// Allows testing if a modification has changed the output of the details API /// /// The testcase can be executed via running the following command on main /// ```bash - /// INSTA_OUTPUT=none INSTA_UPDATE=always DATABASE_URL=postgres://postgres:CHANGE_ME@localhost:5432 cargo test -p navigatum-server test_get_handler_unchanged -- --nocapture --include-ignored + /// INSTA_OUTPUT=none INSTA_UPDATE=always DATABASE_URL=postgres://postgres:CHANGE_ME@localhost:5432 cargo test --package navigatum-server test_get_handler_unchanged -- --nocapture --include-ignored /// ``` /// /// And then running this command on the change /// ```bash - /// DATABASE_URL=postgres://postgres:CHANGE_ME@localhost:5432 cargo insta --review -- -p navigatum-server test_get_handler_unchanged --nocapture --include-ignored + /// DATABASE_URL=postgres://postgres:CHANGE_ME@localhost:5432 cargo insta test --review --package navigatum-server -- test_get_handler_unchanged --nocapture --include-ignored /// ``` /// - /// This is a ..bit.. slow, due to using a [`tokio::task::LocalSet`]. + /// This is a *bit* *slow, due to using a [`tokio::task::LocalSet`]. /// Using multiple cores for this might be possible, but optimising this testcase from 10m is currently not worth it #[ignore] #[actix_web::test] #[tracing_test::traced_test] async fn test_get_handler_unchanged() { - // setup + load data into postgis let pg = PostgresTestContainer::new().await; - for i in 0..20 { - let res = crate::setup::database::load_data(&pg.pool).await; - if let Err(e) = res { - error!("failed to load db because {e:?}. Retrying for 20s"); - tokio::time::sleep(std::time::Duration::from_secs(1)).await; - } else { - info!("successfully initalised the db in try {i}"); - break; - } - } + pg.load_data_retrying().await; let keys: Vec = sqlx::query_scalar!("SELECT key FROM de") .fetch_all(&pg.pool) diff --git a/server/src/setup/tests.rs b/server/src/setup/tests.rs index 1decd930e..aa271b540 100644 --- a/server/src/setup/tests.rs +++ b/server/src/setup/tests.rs @@ -1,6 +1,7 @@ use meilisearch_sdk::client::Client; use testcontainers_modules::testcontainers::{ContainerAsync, ImageExt}; use testcontainers_modules::{meilisearch, testcontainers::runners::AsyncRunner}; +use tracing::{error, info}; pub struct PostgresTestContainer { _container: ContainerAsync, @@ -31,6 +32,20 @@ impl PostgresTestContainer { pool, } } + pub async fn load_data_retrying(&self){ + for i in 0..20 { + let res = crate::setup::database::load_data(&self.pool).await; + if let Err(e) = res { + error!("failed to load db because {e:?}. Retrying for 20s"); + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + } else { + info!("successfully initalised the db in try {i}"); + return; + } + } + + panic!("could not initialise db after 20s") + } } pub struct MeiliSearchTestContainer { @@ -65,16 +80,7 @@ impl MeiliSearchTestContainer { #[tracing_test::traced_test] async fn test_db_setup() { let pg = PostgresTestContainer::new().await; - for i in 0..20 { - let res = crate::setup::database::load_data(&pg.pool).await; - if let Err(e) = res { - tracing::error!("failed to load db because {e:?}. Retrying for 20s"); - tokio::time::sleep(std::time::Duration::from_secs(1)).await; - } else { - tracing::info!("successfully initalised the db in try {i}"); - break; - } - } + pg.load_data_retrying().await; } #[tokio::test]