From ab7e7bad54aa75f85f368f888ea35800dccb0977 Mon Sep 17 00:00:00 2001 From: Tommy Graves Date: Mon, 18 Nov 2024 12:19:15 -0500 Subject: [PATCH 1/2] Adds a --local flag --- crates/abq_cli/src/args.rs | 12 ++++++ crates/abq_cli/src/main.rs | 22 ++++++---- crates/abq_cli/src/workers.rs | 6 ++- crates/abq_cli/tests/cli.rs | 78 +++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 8 deletions(-) diff --git a/crates/abq_cli/src/args.rs b/crates/abq_cli/src/args.rs index faab5644..da052aa6 100644 --- a/crates/abq_cli/src/args.rs +++ b/crates/abq_cli/src/args.rs @@ -245,6 +245,12 @@ pub enum Command { .conflicts_with("tls_key"), ) )] + #[command(group( + ArgGroup::new("local-queue-addr-exclusion") // don't allow both queue_addr and local params + .multiple(false) + .args(["local", "queue_addr"]), + ) + )] Test { /// The number of the test worker connecting for a test suite run. /// @@ -274,6 +280,12 @@ pub enum Command { #[clap(long, required = false, env("RWX_ACCESS_TOKEN"))] access_token: Option, + /// When specified, runs ABQ in local mode only. + /// + /// Cannot be used with --queue-addr since a local queue will be used. + #[clap(long, required = false, env("ABQ_LOCAL"), action)] + local: bool, + /// Address of the queue where the test command will be sent. /// /// Requires that abq workers be started as separate processes connected to the queue. diff --git a/crates/abq_cli/src/main.rs b/crates/abq_cli/src/main.rs index 40aa7ed6..24b968f8 100644 --- a/crates/abq_cli/src/main.rs +++ b/crates/abq_cli/src/main.rs @@ -386,6 +386,7 @@ async fn abq_main() -> anyhow::Result { startup_timeout_seconds, test_strategy, inactivity_timeout_seconds, + local, } => { let deprecations = DeprecationRecord::default(); let stdout_preferences = StdoutPreferences::new(color); @@ -400,14 +401,20 @@ async fn abq_main() -> anyhow::Result { let tls_cert = read_opt_path_bytes(tls_cert)?; let tls_key = read_opt_path_bytes(tls_key)?; - let access_token = access_token.or_else(|| { - let config = abq_config::read_abq_config(get_abq_config_filepath())?; - Some(config.rwx_access_token) - }); + let (access_token, api_config) = if local { + (None, None) + } else { + let access_token = access_token.or_else(|| { + let config = abq_config::read_abq_config(get_abq_config_filepath())?; + Some(config.rwx_access_token) + }); - let api_config = match access_token.as_ref() { - Some(access_token) => Some(get_config_from_api(access_token, &run_id).await?), - None => None, + let api_config = match access_token.as_ref() { + Some(access_token) => Some(get_config_from_api(access_token, &run_id).await?), + None => None, + }; + + (access_token, api_config) }; let ResolvedConfig { @@ -467,6 +474,7 @@ async fn abq_main() -> anyhow::Result { access_token, run_id: run_id.clone(), record_telemetry: queue_location.is_remote(), + queue_location, }; workers::start_workers_standalone( diff --git a/crates/abq_cli/src/workers.rs b/crates/abq_cli/src/workers.rs index bdb1b921..0f11b62a 100644 --- a/crates/abq_cli/src/workers.rs +++ b/crates/abq_cli/src/workers.rs @@ -24,6 +24,7 @@ use signal_hook_tokio::Signals; use crate::reporting::{build_reporters, ReporterKind, StdoutPreferences}; use crate::workers::reporting::create_reporting_task; +use crate::QueueLocation; use self::reporting::ReportingTaskHandle; @@ -39,6 +40,7 @@ pub struct TestRunMetadata { pub access_token: Option, pub run_id: RunId, pub record_telemetry: bool, + pub queue_location: QueueLocation, } pub async fn start_workers_standalone( @@ -188,7 +190,9 @@ async fn do_shutdown( .write_short_summary_lines(&mut stdout, ShortSummaryGrouping::Runner) .unwrap(); println!("\n"); - if execution_mode == ExecutionMode::WriteNormal { + if execution_mode == ExecutionMode::WriteNormal + && test_run_metadata.queue_location.is_remote() + { println!("Run the following command to replay these tests locally:"); println!("\n"); println!( diff --git a/crates/abq_cli/tests/cli.rs b/crates/abq_cli/tests/cli.rs index e68380d6..767be850 100644 --- a/crates/abq_cli/tests/cli.rs +++ b/crates/abq_cli/tests/cli.rs @@ -2816,6 +2816,84 @@ fn test_with_personal_access_token_and_auto_generated_run_id_uses_ephemeral_queu ); } +#[test] +#[with_protocol_version] +#[serial] +fn test_with_access_token_and_local_uses_ephemeral_queue() { + let name = "test_with_access_token_and_local_uses_ephemeral_queue"; + let conf = CSConfigOptions { + use_auth_token: true, + tls: false, + }; + + let server = Server::new(); + let access_token = test_access_token(); + + let manifest = vec![TestOrGroup::test(Test::new( + proto, + "some_test", + [], + Default::default(), + ))]; + let manifest = ManifestMessage::new(Manifest::new(manifest, Default::default())); + + let proto = AbqProtocolVersion::V0_2.get_supported_witness().unwrap(); + + let simulation = [ + Connect, + OpaqueWrite(pack(legal_spawned_message(proto))), + IfGenerateManifest { + then_do: vec![OpaqueWrite(pack(&manifest))], + else_do: vec![ + OpaqueRead, + OpaqueWrite(pack(InitSuccessMessage::new(proto))), + OpaqueRead, + OpaqueWrite(pack(RawTestResultMessage::fake(proto))), + ], + }, + Exit(0), + ]; + let packed = pack_msgs_to_disk(simulation); + + let test_args = { + let simulator = native_runner_simulation_bin(); + let simfile_path = packed.path.display().to_string(); + let args = vec![ + format!("test"), + format!("--worker=1"), + format!("-n=1"), + format!("--local"), + ]; + let mut args = conf.extend_args_for_client(args); + args.extend([s!("--"), simulator, simfile_path]); + args + }; + + let CmdOutput { + stdout, + stderr, + exit_status, + } = Abq::new(format!("{name}_test")) + .args(test_args) + .env([ + ("ABQ_API", &server.url()), + ("RWX_ACCESS_TOKEN", &access_token.to_string()), + ]) + .run(); + assert!( + exit_status.success(), + "STDOUT:\n{stdout}\nSTDERR:\n{stderr}" + ); + assert!( + stdout.contains("1 tests, 0 failures"), + "STDOUT:\n{stdout}\nSTDERR:\n{stderr}" + ); + assert!( + !stdout.contains("Run the following command to replay these tests locally"), + "STDOUT:\n{stdout}\nSTDERR:\n{stderr}" + ); +} + #[test] #[with_protocol_version] #[serial] From acc2aa39ccd5586cf4993ceed1500dc7bbf18af4 Mon Sep 17 00:00:00 2001 From: Tommy Graves Date: Mon, 18 Nov 2024 12:44:27 -0500 Subject: [PATCH 2/2] Bumps to 1.9.0 --- Cargo.lock | 2 +- crates/abq_cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93105551..3298d05a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "abq" -version = "1.8.1" +version = "1.9.0" dependencies = [ "abq_dot_reporter", "abq_hosted", diff --git a/crates/abq_cli/Cargo.toml b/crates/abq_cli/Cargo.toml index 06dc3243..f4a58e79 100644 --- a/crates/abq_cli/Cargo.toml +++ b/crates/abq_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "abq" -version = "1.8.1" +version = "1.9.0" edition = "2021" [dependencies]