diff --git a/scylla/tests/integration/cluster_state_tests.rs b/scylla/tests/integration/cluster_state_tests.rs new file mode 100644 index 0000000000..199acfddae --- /dev/null +++ b/scylla/tests/integration/cluster_state_tests.rs @@ -0,0 +1,30 @@ +use std::env; + +use hashbrown::HashSet; + +use crate::utils::{create_new_session_builder, setup_tracing}; + +#[tokio::test] +#[ntest::timeout(60000)] +#[cfg(not(scylla_cloud_tests))] +async fn test_session_should_have_topology_metadata() { + setup_tracing(); + let session = create_new_session_builder().build().await.unwrap(); + let state = session.get_cluster_state(); + let keys = ["SCYLLA_URI", "SCYLLA_URI2", "SCYLLA_URI3"]; + let expected_addresses: HashSet = keys + .iter() + .map(|key| env::var(key).unwrap_or_else(|_| panic!("{} not set", key))) + .collect(); + + let got_addresses: HashSet = state + .get_nodes_info() + .iter() + .map(|node| node.address.to_string()) + .collect(); + + assert_eq!( + got_addresses, expected_addresses, + "Cluster node addresses do not match environment variables" + ); +} diff --git a/scylla/tests/integration/main.rs b/scylla/tests/integration/main.rs index d69c0aa0ca..a7af828d8e 100644 --- a/scylla/tests/integration/main.rs +++ b/scylla/tests/integration/main.rs @@ -1,5 +1,6 @@ mod authenticate; mod batch; +mod cluster_state_tests; mod consistency; mod cql_collections; mod cql_types; diff --git a/scylla/tests/integration/session.rs b/scylla/tests/integration/session.rs index 6a6b4f4140..9b9c026b05 100644 --- a/scylla/tests/integration/session.rs +++ b/scylla/tests/integration/session.rs @@ -831,6 +831,69 @@ async fn test_get_tracing_info(session: &Session, ks: String) { let tracing_info: TracingInfo = session.get_tracing_info(&tracing_id).await.unwrap(); assert!(!tracing_info.events.is_empty()); assert!(!tracing_info.nodes().is_empty()); + + // Check if the request type matches + assert_eq!(tracing_info.request.as_ref().unwrap(), "Execute CQL3 query"); + + // Check if we're using Scylla or Cassandra + let is_scylla = session + .get_cluster_state() + .get_nodes_info() + .first() + .unwrap() + .sharder() + .is_some(); + + if is_scylla { + // For Scylla, duration should be available immediately + assert!(tracing_info.duration.unwrap() > 0); + } else { + // For Cassandra, we might need to wait for the duration + let mut attempts = 0; + let max_attempts = 10; + let mut duration_opt; + + while attempts < max_attempts { + duration_opt = session + .get_tracing_info(&tracing_id) + .await + .unwrap() + .duration; + if let Some(duration) = duration_opt { + assert!(duration > 0); + break; + } + tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; + attempts += 1; + } + + if attempts == max_attempts { + panic!("Duration was not available after {} attempts", max_attempts); + } + } + + // Verify started_at timestamp is present + assert!(tracing_info.started_at.unwrap().0 > 0); + + // Check parameters + assert!(tracing_info + .parameters + .as_ref() + .unwrap() + .contains_key("consistency_level")); + assert!(tracing_info + .parameters + .as_ref() + .unwrap() + .contains_key("query")); + + // Check events + for event in &tracing_info.events { + assert!(!event.activity.as_ref().unwrap().is_empty()); + assert!(event.source.is_some()); + assert!(event.source_elapsed.unwrap() >= 0); + assert!(!event.activity.as_ref().unwrap().is_empty()); + } } async fn test_tracing_query_iter(session: &Session, ks: String) {