diff options
| author | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-04 08:22:54 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-04 08:22:54 +0300 |
| commit | 4a2cf5b8cbc95bd973e5e2fc8a331ca98f116df0 (patch) | |
| tree | 827ec72e34ce5752aa6007eafde3a75171b2df2f | |
| parent | 6616beba3d6298c49cf2cf77ed63605bf5211168 (diff) | |
| download | genenetwork4-4a2cf5b8cbc95bd973e5e2fc8a331ca98f116df0.tar.gz | |
Fix DB tests: probe SQL_URI credentials, not just the port
The old skip check connected to 127.0.0.1:3306, so tests ran (and failed with 500) whenever a server was listening but the configured credentials were rejected. tests/common/mod.rs now attempts a real connection with the configured SQL_URI; tests skip only when the database is genuinely unusable, and run for real otherwise.
| -rw-r--r-- | tests/common/mod.rs | 14 | ||||
| -rw-r--r-- | tests/group_by_name.rs | 29 | ||||
| -rw-r--r-- | tests/group_strains.rs | 29 | ||||
| -rw-r--r-- | tests/groups.rs | 11 | ||||
| -rw-r--r-- | tests/species.rs | 11 | ||||
| -rw-r--r-- | tests/species_by_name.rs | 20 |
6 files changed, 44 insertions, 70 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 0000000..dcee085 --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,14 @@ +//! Shared helpers for integration tests. + +/// True only when the database in `SQL_URI` actually accepts the +/// configured credentials. Tests that need a live MariaDB skip (rather +/// than fail) when this is false — a server may be listening on the +/// port yet still be unusable (wrong credentials), which a plain port +/// check cannot see. +pub fn db_available() -> bool { + let config = genenetwork4::config::Config::load(); + let Ok(opts) = mysql::Opts::from_url(&config.sql_uri) else { + return false; + }; + mysql::Conn::new(opts).is_ok() +} diff --git a/tests/group_by_name.rs b/tests/group_by_name.rs index d10b7a0..b26a16f 100644 --- a/tests/group_by_name.rs +++ b/tests/group_by_name.rs @@ -4,17 +4,14 @@ use http_body_util::BodyExt; use serde_json::Value; use tower::ServiceExt; +mod common; + /// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather /// than fails when none is reachable, same as species_by_name.rs. #[tokio::test] async fn group_by_name_bxd_returns_group_row() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping group_by_name_bxd_returns_group_row: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping group_by_name_bxd_returns_group_row: no usable database (check SQL_URI credentials)"); return; } @@ -43,13 +40,8 @@ async fn group_by_name_bxd_returns_group_row() { /// up by numeric Id rather than by name. #[tokio::test] async fn group_by_name_numeric_id_returns_same_group_row() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping group_by_name_numeric_id_returns_same_group_row: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping group_by_name_numeric_id_returns_same_group_row: no usable database (check SQL_URI credentials)"); return; } @@ -69,13 +61,8 @@ async fn group_by_name_numeric_id_returns_same_group_row() { #[tokio::test] async fn group_by_name_unknown_group_returns_404() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping group_by_name_unknown_group_returns_404: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping group_by_name_unknown_group_returns_404: no usable database (check SQL_URI credentials)"); return; } diff --git a/tests/group_strains.rs b/tests/group_strains.rs index 7fb22e8..cd97458 100644 --- a/tests/group_strains.rs +++ b/tests/group_strains.rs @@ -4,17 +4,14 @@ use http_body_util::BodyExt; use serde_json::Value; use tower::ServiceExt; +mod common; + /// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather /// than fails when none is reachable, same as group_by_name.rs. #[tokio::test] async fn group_strains_bxd_returns_strains() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping group_strains_bxd_returns_strains: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping group_strains_bxd_returns_strains: no usable database (check SQL_URI credentials)"); return; } @@ -45,14 +42,9 @@ async fn group_strains_bxd_returns_strains() { /// mapping; used_for_mapping=true should filter it out. #[tokio::test] async fn group_strains_used_for_mapping_filters_out_parents() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { + if !common::db_available() { eprintln!( - "skipping group_strains_used_for_mapping_filters_out_parents: no database on 127.0.0.1:3306" + "skipping group_strains_used_for_mapping_filters_out_parents: no usable database (check SQL_URI credentials)" ); return; } @@ -79,13 +71,8 @@ async fn group_strains_used_for_mapping_filters_out_parents() { #[tokio::test] async fn group_strains_unknown_group_returns_404() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping group_strains_unknown_group_returns_404: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping group_strains_unknown_group_returns_404: no usable database (check SQL_URI credentials)"); return; } diff --git a/tests/groups.rs b/tests/groups.rs index 3966ac4..d9aba36 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -4,19 +4,16 @@ use http_body_util::BodyExt; use serde_json::Value; use tower::ServiceExt; +mod common; + /// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather /// than fails when none is reachable, same as species.rs. BXD is used /// everywhere as a test fixture in the GeneNetwork2/GeneNetwork3 test /// suites and is always present in the database. #[tokio::test] async fn groups_returns_ok_with_bxd() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping groups_returns_ok_with_bxd: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping groups_returns_ok_with_bxd: no usable database (check SQL_URI credentials)"); return; } diff --git a/tests/species.rs b/tests/species.rs index 0717c7b..795f8f4 100644 --- a/tests/species.rs +++ b/tests/species.rs @@ -4,6 +4,8 @@ use http_body_util::BodyExt; use serde_json::Value; use tower::ServiceExt; +mod common; + /// Unlike hello_world/version, /species needs a live MariaDB connection /// (SQL_URI, see src/db.rs). There is no database reachable inside the /// Guix build sandbox, so this test checks connectivity first and skips @@ -11,13 +13,8 @@ use tower::ServiceExt; /// none is available. #[tokio::test] async fn species_returns_ok_with_species_list() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping species_returns_ok_with_species_list: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping species_returns_ok_with_species_list: no usable database (check SQL_URI credentials)"); return; } diff --git a/tests/species_by_name.rs b/tests/species_by_name.rs index 097d61c..1e11bd6 100644 --- a/tests/species_by_name.rs +++ b/tests/species_by_name.rs @@ -4,17 +4,14 @@ use http_body_util::BodyExt; use serde_json::Value; use tower::ServiceExt; +mod common; + /// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather /// than fails when none is reachable, same as species.rs. #[tokio::test] async fn species_by_name_mouse_returns_species_row() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping species_by_name_mouse_returns_species_row: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping species_by_name_mouse_returns_species_row: no usable database (check SQL_URI credentials)"); return; } @@ -40,13 +37,8 @@ async fn species_by_name_mouse_returns_species_row() { #[tokio::test] async fn species_by_name_unknown_species_returns_404() { - if std::net::TcpStream::connect_timeout( - &"127.0.0.1:3306".parse().unwrap(), - std::time::Duration::from_millis(500), - ) - .is_err() - { - eprintln!("skipping species_by_name_unknown_species_returns_404: no database on 127.0.0.1:3306"); + if !common::db_available() { + eprintln!("skipping species_by_name_unknown_species_returns_404: no usable database (check SQL_URI credentials)"); return; } |
