Skip to content

Commit

Permalink
Refactor zk e2e tests'
Browse files Browse the repository at this point in the history
Signed-off-by: Xudong Sun <[email protected]>
  • Loading branch information
marshtompsxd committed Sep 13, 2023
1 parent bea0fa3 commit a0317c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
8 changes: 8 additions & 0 deletions e2e/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use kube::{
discovery::{ApiCapabilities, ApiResource, Discovery, Scope},
Client, CustomResource,
};
use std::process::Command;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error("Failed to get kube client: {0}")]
Expand Down Expand Up @@ -120,3 +122,9 @@ pub async fn get_output_and_err(mut attached: AttachedProcess) -> (String, Strin
attached.join().await.unwrap();
(out, err)
}

pub fn run_command(program: &str, args: Vec<&str>, err_msg: &str) {
let cmd = Command::new(program).args(args).output().expect(err_msg);
println!("cmd output: {}", String::from_utf8_lossy(&cmd.stdout));
println!("cmd error: {}", String::from_utf8_lossy(&cmd.stderr));
}
39 changes: 12 additions & 27 deletions e2e/src/zookeeper_e2e.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
use k8s_openapi::api::core::v1::{ConfigMap, Pod};
use k8s_openapi::api::{apps::v1::StatefulSet, core::v1::Service};
use k8s_openapi::api::apps::v1::StatefulSet;
use k8s_openapi::api::core::v1::{ConfigMap, Pod, Service};
use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition;
use kube::{
api::{
Expand All @@ -16,7 +16,6 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::path::PathBuf;
use std::process::Command;
use std::thread;
use std::time::{Duration, Instant};
use tokio::time::sleep;
Expand Down Expand Up @@ -159,24 +158,17 @@ pub async fn scaling_test(client: Client, zk_name: String) -> Result<(), Error>
let timeout = Duration::from_secs(360);
let start = Instant::now();
let sts_api: Api<StatefulSet> = Api::default_namespaced(client.clone());
let scale_output = Command::new("kubectl")
.args([
run_command(
"kubectl",
vec![
"patch",
"zk",
"zookeeper",
"--type=json",
"-p",
"[{\"op\": \"replace\", \"path\": \"/spec/replicas\", \"value\": 2}]",
])
.output()
.expect("failed to scale zk");
println!(
"cmd output: {}",
String::from_utf8_lossy(&scale_output.stdout)
);
println!(
"cmd error: {}",
String::from_utf8_lossy(&scale_output.stderr)
],
"failed to scale zk",
);

loop {
Expand Down Expand Up @@ -228,24 +220,17 @@ pub async fn scaling_test(client: Client, zk_name: String) -> Result<(), Error>
};
}

Command::new("kubectl")
.args([
run_command(
"kubectl",
vec![
"patch",
"zk",
"zookeeper",
"--type=json",
"-p",
"[{\"op\": \"replace\", \"path\": \"/spec/replicas\", \"value\": 3}]",
])
.output()
.expect("failed to scale zk");
println!(
"cmd output: {}",
String::from_utf8_lossy(&scale_output.stdout)
);
println!(
"cmd error: {}",
String::from_utf8_lossy(&scale_output.stderr)
],
"failed to scale zk",
);

loop {
Expand Down

0 comments on commit a0317c1

Please sign in to comment.