Skip to content

Commit

Permalink
added fixes for bugs which the new testcase revealed
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Nov 2, 2024
1 parent 2b077e2 commit 01083bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
25 changes: 8 additions & 17 deletions server/src/locations/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ struct OverlayMapEntry {
}

#[derive(Deserialize, Serialize, Debug, Default)]
#[serde(rename_all = "snake_case")]
enum DefaultMaps {
#[default]
Interactive,
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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<String> = sqlx::query_scalar!("SELECT key FROM de")
.fetch_all(&pg.pool)
Expand Down
26 changes: 16 additions & 10 deletions server/src/setup/tests.rs
Original file line number Diff line number Diff line change
@@ -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<testcontainers_modules::postgres::Postgres>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 01083bd

Please sign in to comment.