Skip to content

Commit

Permalink
correct PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
musitdev committed Jun 17, 2024
1 parent da13685 commit 0d312b5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 48 deletions.
6 changes: 2 additions & 4 deletions networks/suzuka/suzuka-client/bin/basic_alice_bob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ impl Scenario for BasicScenario {
let node_url = Url::from_str(
format!("http://{}", suzuka_config.aptos_config.aptos_rest_listen_url.as_str())
.as_str(),
)
.unwrap();
)?;

let faucet_url = Url::from_str(
format!("http://{}", suzuka_config.aptos_config.aptos_faucet_listen_url.as_str())
.as_str(),
)
.unwrap();
)?;

let rest_client = Client::new(node_url.clone());
let faucet_client = FaucetClient::new(faucet_url.clone(), node_url.clone()); // <:!:section_1a
Expand Down
2 changes: 1 addition & 1 deletion networks/suzuka/suzuka-client/bin/demo_scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
min_scenarios: 6,
max_scenarios: 10,
duration: std::time::Duration::from_secs(20),
nb_clycle: 4,
number_clycle: 4,
};

// Init the Test before execution
Expand Down
78 changes: 38 additions & 40 deletions networks/suzuka/suzuka-client/src/load_soak_testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ pub struct ExecutionConfig {
pub logfile: String,
/// The path to the file where execution data are written to be processed later.
pub execfile: String,
/// The number of started scenarios per client. nb_scenarios / nb_scenario_per_client defines the number of clients.
pub nb_scenario_per_client: usize,
/// The number of started scenarios per client. number_scenarios / number_scenario_per_client defines the number of clients.
pub number_scenario_per_client: usize,
}

impl ExecutionConfig {
fn verify_config(&self) {
match self.kind {
TestKind::Load { nb_scenarios } => {
TestKind::Load { number_scenarios } => {
assert!(
nb_scenarios >= self.nb_scenario_per_client,
number_scenarios >= self.number_scenario_per_client,
"Number of running scenario less than the number if scenario per client."
);
}
TestKind::Soak { min_scenarios, max_scenarios, .. } => {
assert!(max_scenarios >= min_scenarios, "max scenarios less than min scenarios");
assert!(
min_scenarios >= self.nb_scenario_per_client,
min_scenarios >= self.number_scenario_per_client,
"Number of min running scenario less than the number if scenario per client."
);
}
Expand All @@ -86,48 +86,49 @@ impl ExecutionConfig {

impl Default for ExecutionConfig {
fn default() -> Self {
let nb_scenarios: usize = std::env::var("LOADTEST_NB_SCENARIO")
let number_scenarios: usize = std::env::var("LOADTEST_NUMBER_SCENARIO")
.map_err(|err| err.to_string())
.and_then(|val| val.parse().map_err(|err: std::num::ParseIntError| err.to_string()))
.unwrap_or(10);
let nb_scenario_per_client: usize = std::env::var("LOADTEST_NB_SCENARIO_PER_CLIENT")
.unwrap_or("2".to_string())
.parse()
.unwrap_or(2);
let number_scenario_per_client: usize =
std::env::var("LOADTEST_NUMBER_SCENARIO_PER_CLIENT")
.unwrap_or("2".to_string())
.parse()
.unwrap_or(2);
ExecutionConfig {
kind: TestKind::build_load_test(nb_scenarios),
kind: TestKind::build_load_test(number_scenarios),
logfile: "log_file.txt".to_string(),
execfile: "test_result.txt".to_string(),
nb_scenario_per_client,
number_scenario_per_client,
}
}
}

/// Define the type of test to run:
#[derive(Clone, Debug)]
pub enum TestKind {
/// Load: try to run all scenario (nb_scenarios) concurrently
Load { nb_scenarios: usize },
/// Soak: start min_scenarios at first then increase the number to max_scenarios then decrease and do nb_clycle during duration
/// Load: try to run all scenario (number_scenarios) concurrently
Load { number_scenarios: usize },
/// Soak: start min_scenarios at first then increase the number to max_scenarios then decrease and do number_clycle during duration
Soak {
min_scenarios: usize,
max_scenarios: usize,
duration: std::time::Duration,
nb_clycle: u32,
number_clycle: u32,
},
}

impl TestKind {
pub fn build_load_test(nb_scenarios: usize) -> Self {
TestKind::Load { nb_scenarios }
pub fn build_load_test(number_scenarios: usize) -> Self {
TestKind::Load { number_scenarios }
}
pub fn build_soak_test(
min_scenarios: usize,
max_scenarios: usize,
duration: std::time::Duration,
nb_clycle: u32,
number_clycle: u32,
) -> Self {
TestKind::Soak { min_scenarios, max_scenarios, duration, nb_clycle }
TestKind::Soak { min_scenarios, max_scenarios, duration, number_clycle }
}
}

Expand All @@ -138,16 +139,16 @@ impl TestKind {
pub fn execute_test(config: ExecutionConfig, create_scenario: Arc<scenario::CreateScenarioFn>) {
tracing::info!("Start test scenario execution.");

let nb_scenarios = match config.kind {
TestKind::Load { nb_scenarios } => nb_scenarios,
let number_scenarios = match config.kind {
TestKind::Load { number_scenarios } => number_scenarios,
TestKind::Soak { max_scenarios, .. } => max_scenarios,
};

//build chunk of ids. Start at 1. 0 mean in result execution fail before scenario can execute.
let ids: Vec<_> = (1..=nb_scenarios).collect();
let ids: Vec<_> = (1..=number_scenarios).collect();
let chunks: Vec<_> = ids
.into_iter()
.chunks(config.nb_scenario_per_client)
.chunks(config.number_scenario_per_client)
.into_iter()
.map(|chunk| {
(config.kind.clone(), chunk.into_iter().collect::<Vec<_>>(), create_scenario.clone())
Expand Down Expand Up @@ -203,7 +204,7 @@ impl TestClient {
};
let scenario_results = match kind {
TestKind::Load { .. } => rt.block_on(self.load_runner(create_scanario.clone())),
TestKind::Soak { min_scenarios, max_scenarios, duration, nb_clycle } => {
TestKind::Soak { min_scenarios, max_scenarios, duration, number_clycle } => {
// The scenario that run all the time and part time are divided using the client.
// min_scenarios first ids are run permanently, the others client run part time.
//ids start at 1.
Expand All @@ -217,10 +218,10 @@ impl TestClient {
// min_scenarios run all the time.
// The others scenarios start after some time (start delta time) then run the same time: Part-time scenario duration
// max_scenarios - min_scenarios scenarios run part-time depending on the number of cycle.
// Part-time scenario duration max: Duration / (nbcycle * 2)
// Part-time scenario duration max: Duration / (number_cycle * 2)
// scenario start delta: (Part-time scenario duration max * scenario index / nb scenario) + (Duration * current cycle / nb cycle)
let nb_part_time_scenario: u32 = (max_scenarios - min_scenarios) as u32;
let parttime_scenario_duration = duration / (nb_clycle * 2);
let number_part_time_scenario: u32 = (max_scenarios - min_scenarios) as u32;
let parttime_scenario_duration = duration / (number_clycle * 2);
vec![]
}
}
Expand Down Expand Up @@ -248,16 +249,16 @@ impl TestClient {
while let Some(res) = set.join_next().await {
let elapse = start_time.elapsed().as_millis();
let metrics = match res {
Ok((id, Ok(()))) => ScenarioExecMetric::new_ok(id, elapse),
Ok((id, Ok(()))) => ScenarioExecMetric::new(id, elapse, ScenarioExecResult::Ok),
Ok((id, Err(err))) => {
let log = format!("Scenario:{id} execution failed because: {err}");
tracing::info!(target:EXEC_LOG_FILTER, log);
tracing::warn!(log);
ScenarioExecMetric::new_err(id, elapse)
ScenarioExecMetric::new(id, elapse, ScenarioExecResult::Fail)
}
Err(err) => {
tracing::warn!("Error during scenario spawning: {err}");
ScenarioExecMetric::new_err(0, elapse)
ScenarioExecMetric::new(0, elapse, ScenarioExecResult::Fail)
}
};
let metrics_scenario = serde_json::to_string(&metrics)
Expand Down Expand Up @@ -288,18 +289,18 @@ impl TestClient {
let mut scenario_results = vec![];
while let Some(res) = set.join_next().await {
let metrics = match res {
Ok((id, Ok(elapse))) => ScenarioExecMetric::new_ok(id, elapse),
Ok((id, Ok(elapse))) => ScenarioExecMetric::new(id, elapse, ScenarioExecResult::Ok),
Ok((id, Err(err))) => {
let log = format!("Scenario:{id} execution failed because: {err}");
tracing::info!(target:EXEC_LOG_FILTER, log);
tracing::warn!(log);
let elapse = initial_start_time.elapsed().as_millis();
ScenarioExecMetric::new_err(id, elapse)
ScenarioExecMetric::new(id, elapse, ScenarioExecResult::Fail)
}
Err(err) => {
tracing::warn!("Error during scenario spawning: {err}");
let elapse = initial_start_time.elapsed().as_millis();
ScenarioExecMetric::new_err(0, elapse)
ScenarioExecMetric::new(0, elapse, ScenarioExecResult::Fail)
}
};
let metrics_scenario = serde_json::to_string(&metrics)
Expand All @@ -315,7 +316,7 @@ async fn run_scenarion_in_loop(
id: usize,
create_scanario: Arc<scenario::CreateScenarioFn>,
duration: Duration,
) -> anyhow::Result<u128> {
) -> Result<u128, anyhow::Error> {
let start_time = std::time::Instant::now();
let mut average_time = 0;
loop {
Expand Down Expand Up @@ -347,11 +348,8 @@ struct ScenarioExecMetric {
}

impl ScenarioExecMetric {
fn new_ok(scenario_id: usize, elapse_millli: u128) -> Self {
ScenarioExecMetric { scenario_id, elapse_millli, result: ScenarioExecResult::Ok }
}
fn new_err(scenario_id: usize, elapse_millli: u128) -> Self {
ScenarioExecMetric { scenario_id, elapse_millli, result: ScenarioExecResult::Fail }
fn new(scenario_id: usize, elapse_millli: u128, result: ScenarioExecResult) -> Self {
ScenarioExecMetric { scenario_id, elapse_millli, result }
}

fn is_ok(&self) -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::EXEC_LOG_FILTER;
use anyhow::Result;

/// A scenario is any struct that implements the Scenario trait.
/// To ease scenario execution and logs, an id (usize) is provided during creation.
Expand All @@ -14,7 +13,7 @@ use anyhow::Result;
/// Return the execution result. If the scenario fails, return an error.
#[async_trait::async_trait]
pub trait Scenario {
async fn run(self: Box<Self>) -> Result<()>;
async fn run(self: Box<Self>) -> Result<(), anyhow::Error>;

fn log_exec_info(&self, msg: &str) {
tracing::info!(target:EXEC_LOG_FILTER, msg);
Expand Down
2 changes: 1 addition & 1 deletion process-compose/suzuka-full-node/process-compose.load.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ processes:

suzuka-client-loadtests:
command: |
LOADTEST_NB_SCENARIO=1 LOADTEST_NB_SCENARIO_PER_CLIENT=1 cargo run -p suzuka-client --bin basic_alice_bob
LOADTEST_NUMBER_SCENARIO=1 LOADTEST_NUMBER_SCENARIO_PER_CLIENT=1 cargo run -p suzuka-client --bin basic_alice_bob
depends_on:
suzuka-full-node:
condition: process_healthy
Expand Down

0 comments on commit 0d312b5

Please sign in to comment.