scylla/utils/
test_utils.rs#[cfg(test)]
use crate::transport::session_builder::{GenericSessionBuilder, SessionBuilderKind};
#[cfg(test)]
use crate::Session;
#[cfg(test)]
use std::{num::NonZeroU32, time::Duration};
use std::{
sync::atomic::{AtomicUsize, Ordering},
time::{SystemTime, UNIX_EPOCH},
};
static UNIQUE_COUNTER: AtomicUsize = AtomicUsize::new(0);
pub fn unique_keyspace_name() -> String {
let cnt = UNIQUE_COUNTER.fetch_add(1, Ordering::SeqCst);
let name = format!(
"test_rust_{}_{}",
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs(),
cnt
);
println!("Unique name: {}", name);
name
}
#[cfg(test)]
pub(crate) async fn supports_feature(session: &Session, feature: &str) -> bool {
let meta = session.get_cluster_data();
let system_local = meta
.keyspaces
.get("system")
.unwrap()
.tables
.get("local")
.unwrap();
if !system_local.columns.contains_key("supported_features") {
return false;
}
let (features,): (Option<String>,) = session
.query("SELECT supported_features FROM system.local", ())
.await
.unwrap()
.single_row_typed()
.unwrap();
features
.unwrap_or_default()
.split(',')
.any(|f| f == feature)
}
#[cfg(test)]
pub fn create_new_session_builder() -> GenericSessionBuilder<impl SessionBuilderKind> {
let session_builder = {
#[cfg(not(scylla_cloud_tests))]
{
use crate::SessionBuilder;
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
SessionBuilder::new().known_node(uri)
}
#[cfg(scylla_cloud_tests)]
{
use crate::transport::session_builder::CloudMode;
use crate::CloudSessionBuilder;
use std::path::Path;
std::env::var("CLOUD_CONFIG_PATH")
.map(|config_path| CloudSessionBuilder::new(Path::new(&config_path)))
.expect("Failed to initialize CloudSessionBuilder")
.expect("CLOUD_CONFIG_PATH environment variable is missing")
}
};
session_builder
.tracing_info_fetch_attempts(NonZeroU32::new(50).unwrap())
.tracing_info_fetch_interval(Duration::from_millis(200))
}