From 74daf2f1b3491843a2dd13fe557f0bb502355276 Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:40:56 -0500 Subject: [PATCH] Drop support for ABQ statefiles (#33) Co-authored-by: Michael Glass --- crates/abq_cli/src/main.rs | 3 -- crates/abq_cli/src/statefile.rs | 45 --------------------- crates/abq_cli/tests/cli.rs | 72 --------------------------------- 3 files changed, 120 deletions(-) delete mode 100644 crates/abq_cli/src/statefile.rs diff --git a/crates/abq_cli/src/main.rs b/crates/abq_cli/src/main.rs index 77248435..47a00f3e 100644 --- a/crates/abq_cli/src/main.rs +++ b/crates/abq_cli/src/main.rs @@ -4,7 +4,6 @@ mod health; mod instance; mod report; mod reporting; -mod statefile; mod workers; use std::io; @@ -436,8 +435,6 @@ async fn abq_main() -> anyhow::Result { _ => ExecutionMode::WriteNormal, }; - statefile::optional_write_worker_statefile(&run_id)?; - let runner = RunnerKind::GenericNativeTestRunner(runner_params); let max_run_number = 1 + retries; diff --git a/crates/abq_cli/src/statefile.rs b/crates/abq_cli/src/statefile.rs deleted file mode 100644 index bc5e99bf..00000000 --- a/crates/abq_cli/src/statefile.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::{ - fs, - io::Write, - path::{Path, PathBuf}, -}; - -use abq_utils::net_protocol::workers::RunId; -use serde_derive::Serialize; - -#[derive(Serialize)] -struct WorkerState<'a> { - abq_executable: &'a Path, - abq_version: &'a str, - run_id: &'a RunId, -} - -/// Optionally writes a statefile for an ABQ worker invocation, if the invocation state indicates so. -/// -/// Intended for integration with Captain. See RWX RFC#18. -pub(crate) fn optional_write_worker_statefile(run_id: &RunId) -> anyhow::Result<()> { - let statefile = match std::env::var("ABQ_STATE_FILE") { - Ok(path_s) => PathBuf::from(path_s), - Err(_) => { - // statefile var not present, don't write it. - return Ok(()); - } - }; - - let state = WorkerState { - abq_executable: &std::env::current_exe()?, - abq_version: abq_utils::VERSION, - run_id, - }; - - let mut statefile = fs::OpenOptions::new() - .create(true) - .truncate(true) - .write(true) - .open(statefile)?; - - serde_json::to_writer(&statefile, &state)?; - statefile.flush()?; - - Ok(()) -} diff --git a/crates/abq_cli/tests/cli.rs b/crates/abq_cli/tests/cli.rs index 9a0cae92..2f5d57ad 100644 --- a/crates/abq_cli/tests/cli.rs +++ b/crates/abq_cli/tests/cli.rs @@ -21,7 +21,6 @@ use mockito::{Matcher, Server}; use regex::Regex; use serde_json as json; use serial_test::serial; -use std::fs::File; use std::ops::{Deref, DerefMut}; use std::process::{ChildStderr, ChildStdout, ExitStatus, Output}; use std::str::FromStr; @@ -1181,77 +1180,6 @@ test_all_network_config_options! { } } -fn verify_and_sanitize_state(state: &mut json::Map) { - { - let exe_cell = state - .get_mut("abq_executable") - .expect("abq_executable missing"); - let exe_path = Path::new(exe_cell.as_str().unwrap()); - assert_eq!(exe_path, abq_binary()); - *exe_cell = json::json!(""); - } - - { - let version_cell = state.get_mut("abq_version").expect("abq_version missing"); - assert_eq!(version_cell.as_str().unwrap(), abq_utils::VERSION); - *version_cell = json::json!(""); - } -} - -#[test] -fn write_statefile_for_worker() { - let name = "write_statefile_for_worker"; - let conf = CSConfigOptions { - use_auth_token: false, - tls: false, - }; - - let statefile = tempfile::NamedTempFile::new().unwrap().into_temp_path(); - let statefile = statefile.to_path_buf(); - - let (queue_proc, queue_addr) = setup_queue!(name, conf); - - let test_args = |worker: usize| { - vec![ - format!("test"), - format!("--worker={worker}"), - format!("--reporter=dot"), - format!("--queue-addr={queue_addr}"), - format!("--working-dir=."), - format!("--run-id=my-test-run-id"), - format!("--num=cpu-cores"), - format!("--color=never"), - format!("--"), - format!("__zzz_not_a_command__"), - ] - }; - - let mut worker0 = Abq::new("write_statefile_for_worker0") - .args(test_args(0)) - .spawn(); - - let _worker1 = Abq::new("write_statefile_for_worker0") - .args(test_args(1)) - .env([("ABQ_STATE_FILE", statefile.display().to_string())]) - .run(); - - worker0.kill().unwrap(); - term(queue_proc); - - let statefile = File::open(&statefile).unwrap(); - let mut state = serde_json::from_reader(&statefile).unwrap(); - - verify_and_sanitize_state(&mut state); - - insta::assert_json_snapshot!(state, @r###" - { - "abq_executable": "", - "abq_version": "", - "run_id": "my-test-run-id" - } - "###); -} - test_all_network_config_options! { native_runner_fails_while_executing_test |name, conf: CSConfigOptions| { let (queue_proc, queue_addr) = setup_queue!(name, conf);