Skip to content

Commit

Permalink
Merge pull request #281 from shachlanAmazon/flakey-test
Browse files Browse the repository at this point in the history
Increase timeout for cluster creation.
  • Loading branch information
shachlanAmazon authored Jun 22, 2023
2 parents c945e42 + f72b949 commit fc1c028
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
30 changes: 20 additions & 10 deletions babushka-core/tests/utilities/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl RedisCluster {
script_args.push("-r");
script_args.push(&replicas_num);
}
let output: String = Self::execute_cluster_script(script_args, use_tls, None);
let (cluster_folder, addresses) = Self::parse_start_script_output(&output);
let (stdout, stderr) = Self::execute_cluster_script(script_args, use_tls, None);
let (cluster_folder, addresses) = Self::parse_start_script_output(&stdout, &stderr);
let mut password: Option<String> = None;
if let Some(info) = conn_info {
password = info.password.clone();
Expand All @@ -83,19 +83,21 @@ impl RedisCluster {
}
}

fn parse_start_script_output(output: &str) -> (String, Vec<AddressInfo>) {
fn parse_start_script_output(output: &str, errors: &str) -> (String, Vec<AddressInfo>) {
let cluster_folder = output.split("CLUSTER_FOLDER=").collect::<Vec<&str>>();
assert!(
!cluster_folder.is_empty() && cluster_folder.len() >= 2,
"{:?}",
cluster_folder
"Received output: {output}, stderr: {errors}"
);
let cluster_folder = cluster_folder.get(1).unwrap().lines();
let cluster_folder = cluster_folder.collect::<Vec<&str>>();
let cluster_folder = cluster_folder.first().unwrap().to_string();

let output_parts = output.split("CLUSTER_NODES=").collect::<Vec<&str>>();
assert!(!output_parts.is_empty() && output_parts.len() >= 2);
assert!(
!output_parts.is_empty() && output_parts.len() >= 2,
"Received output: {output}, stderr: {errors}"
);
let nodes = output_parts.get(1).unwrap().split(',');
let mut address_vec: Vec<AddressInfo> = Vec::new();
for node in nodes {
Expand All @@ -108,7 +110,11 @@ impl RedisCluster {
(cluster_folder, address_vec)
}

fn execute_cluster_script(args: Vec<&str>, use_tls: bool, password: Option<String>) -> String {
fn execute_cluster_script(
args: Vec<&str>,
use_tls: bool,
password: Option<String>,
) -> (String, String) {
let python_binary = which("python3").unwrap();
let mut script_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
script_path.push("../utils/cluster_manager.py");
Expand Down Expand Up @@ -137,11 +143,15 @@ impl RedisCluster {
.output()
.expect("failed to execute process")
};
let parsed_output = output.stdout;
std::str::from_utf8(&parsed_output)
let parsed_stdout = std::str::from_utf8(&output.stdout)
.unwrap()
.trim()
.to_string();
let parsed_stderr = std::str::from_utf8(&output.stderr)
.unwrap()
.trim()
.to_string()
.to_string();
(parsed_stdout, parsed_stderr)
}

pub fn get_server_addresses(&self) -> Vec<ConnectionAddr> {
Expand Down
1 change: 0 additions & 1 deletion babushka-core/tests/utilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ where
}

pub async fn setup_acl(addr: &ConnectionAddr, connection_info: &RedisConnectionInfo) {
println!("setup acl!");
let client = redis::Client::open(redis::ConnectionInfo {
addr: addr.clone(),
redis: RedisConnectionInfo::default(),
Expand Down
2 changes: 1 addition & 1 deletion utils/cluster_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def create_cluster(
stderr=subprocess.PIPE,
text=True,
)
output, err = p.communicate(timeout=10)
output, err = p.communicate(timeout=20)
if err or "[OK] All 16384 slots covered." not in output:
raise Exception(f"Failed to create cluster: {err if err else output}")

Expand Down

0 comments on commit fc1c028

Please sign in to comment.