Skip to content

Commit

Permalink
Fix parameter logic with run-forever
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeling committed Oct 8, 2024
1 parent 5718299 commit 5307bff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
25 changes: 9 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Args {
long,
short,
display_order = 1,
default_value_t = 8,
default_value_t = 0,
conflicts_with = "run_forever"
)]
duration: u64,
Expand All @@ -57,7 +57,7 @@ struct Args {
port: u64,

/// Seconds to run (skip) before measuring the latency.
#[clap(long, display_order = 5, value_name = "DURATION", default_value_t = 4)]
#[clap(long, display_order = 5, value_name = "DURATION", default_value_t = 0)]
skip_seconds: u64,

/// Print more details in the summary result
Expand All @@ -79,7 +79,7 @@ struct Args {
action = clap::ArgAction::SetTrue,
display_order = 8,
conflicts_with = "duration",
default_value_t = false
default_value_t = true
)]
run_forever: bool,

Expand Down Expand Up @@ -124,12 +124,15 @@ async fn main() -> Result<()> {

let shutdown_handler = setup_shutdown_handler();

if args.duration <= args.skip_seconds {
let mut run_forever = args.run_forever;
if args.duration < args.skip_seconds {
eprintln!(
"Error: `duration` ({}) cannot be equal or smaller than `skip_seconds` ({}).",
"Error: `duration` ({}) cannot be smaller than `skip_seconds` ({}).",
args.duration, args.skip_seconds
);
std::process::exit(1);
} else if args.duration > 0 && args.skip_seconds > 0 {
run_forever = false;
}

let mut api = Api::KuksaValV1;
Expand All @@ -141,16 +144,6 @@ async fn main() -> Result<()> {

let config_groups = read_config(args.test_data_file.as_ref())?;

for group in &config_groups {
if group.cycle_time_ms as u64 >= args.duration * 1000 {
eprintln!(
"Error: Group name: {} contain a higher or equal cycle_time_ms: {} seconds than the specified test --duration: {} seconds.",
group.group_name, group.cycle_time_ms / 1000, args.duration
);
std::process::exit(1);
}
}

check_duplicate_paths(&config_groups);
// Skip at most _iterations_ number of iterations
let skip_seconds = max(0, min(args.duration, args.skip_seconds));
Expand All @@ -162,7 +155,7 @@ async fn main() -> Result<()> {
interval: 0,
skip_seconds,
api,
run_forever: args.run_forever,
run_forever,
detailed_output: args.detailed_output,
};

Expand Down
4 changes: 3 additions & 1 deletion src/measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,15 @@ pub async fn perform_measurement(

// Stop the execution of tasks when the test duration is exceeded.
task::spawn(async move {
while start_run.elapsed().as_millis() < duration.into()
while (measurement_config.run_forever || start_run.elapsed().as_millis() < duration.into())
&& shutdown_handler_ref
.read()
.await
.state
.running
.load(Ordering::SeqCst)
{}
println!("Finished");
if shutdown_handler_ref.write().await.trigger.send(()).is_err() {
println!("failed to trigger shutdown");
}
Expand Down Expand Up @@ -340,6 +341,7 @@ async fn measurement_loop(ctx: &mut MeasurementContext) -> Result<(u64, u64)> {
.running
.load(Ordering::SeqCst)
{
println!("Stoopped");
break;
}

Expand Down

0 comments on commit 5307bff

Please sign in to comment.