Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulator: exit with ExitCode::FAILURE if an error was returned in any simulation #691

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion simulator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ use runner::io::SimulatorIO;
use std::backtrace::Backtrace;
use std::io::Write;
use std::path::Path;
use std::process::ExitCode;
use std::sync::Arc;
use tempfile::TempDir;

mod generation;
mod model;
mod runner;

fn main() {
fn main() -> ExitCode {
init_logger();

let cli_opts = SimulatorCLI::parse();
Expand Down Expand Up @@ -62,6 +63,8 @@ fn main() {

let result = std::panic::catch_unwind(|| run_simulation(seed, &cli_opts, &db_path, &plan_path));

let mut error_triggered = false;

if cli_opts.doublecheck {
// Move the old database and plan file to a new location
let old_db_path = db_path.with_extension("_old.db");
Expand All @@ -77,36 +80,43 @@ fn main() {
match (result, result2) {
(Ok(Ok(_)), Err(_)) => {
log::error!("doublecheck failed! first run succeeded, but second run panicked.");
error_triggered = true;
}
(Ok(Err(_)), Err(_)) => {
log::error!(
"doublecheck failed! first run failed assertion, but second run panicked."
);
error_triggered = true;
}
(Err(_), Ok(Ok(_))) => {
log::error!("doublecheck failed! first run panicked, but second run succeeded.");
error_triggered = true;
}
(Err(_), Ok(Err(_))) => {
log::error!(
"doublecheck failed! first run panicked, but second run failed assertion."
);
error_triggered = true;
}
(Ok(Ok(_)), Ok(Err(_))) => {
log::error!(
"doublecheck failed! first run succeeded, but second run failed assertion."
);
error_triggered = true;
}
(Ok(Err(_)), Ok(Ok(_))) => {
log::error!(
"doublecheck failed! first run failed assertion, but second run succeeded."
);
error_triggered = true;
}
(Err(_), Err(_)) | (Ok(_), Ok(_)) => {
// Compare the two database files byte by byte
let old_db = std::fs::read(&old_db_path).unwrap();
let new_db = std::fs::read(&db_path).unwrap();
if old_db != new_db {
log::error!("doublecheck failed! database files are different.");
error_triggered = true;
} else {
log::info!("doublecheck succeeded! database files are the same.");
}
Expand All @@ -130,13 +140,21 @@ fn main() {
}
Err(e) => {
log::error!("simulation failed: {:?}", e);
error_triggered = true;
}
}
} else {
error_triggered = true;
}
// Print the seed, the locations of the database and the plan file at the end again for easily accessing them.
println!("database path: {:?}", db_path);
println!("simulator plan path: {:?}", plan_path);
println!("seed: {}", seed);

match error_triggered {
true => ExitCode::FAILURE,
false => ExitCode::SUCCESS,
}
}

fn run_simulation(
Expand Down
Loading