Skip to content

Commit

Permalink
Adds a --local flag (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
TAGraves authored Nov 18, 2024
1 parent 318ecb8 commit 585f436
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/abq_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "abq"
version = "1.8.1"
version = "1.9.0"
edition = "2021"

[dependencies]
Expand Down
12 changes: 12 additions & 0 deletions crates/abq_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -274,6 +280,12 @@ pub enum Command {
#[clap(long, required = false, env("RWX_ACCESS_TOKEN"))]
access_token: Option<AccessToken>,

/// 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.
Expand Down
22 changes: 15 additions & 7 deletions crates/abq_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ async fn abq_main() -> anyhow::Result<ExitCode> {
startup_timeout_seconds,
test_strategy,
inactivity_timeout_seconds,
local,
} => {
let deprecations = DeprecationRecord::default();
let stdout_preferences = StdoutPreferences::new(color);
Expand All @@ -400,14 +401,20 @@ async fn abq_main() -> anyhow::Result<ExitCode> {
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 {
Expand Down Expand Up @@ -467,6 +474,7 @@ async fn abq_main() -> anyhow::Result<ExitCode> {
access_token,
run_id: run_id.clone(),
record_telemetry: queue_location.is_remote(),
queue_location,
};

workers::start_workers_standalone(
Expand Down
6 changes: 5 additions & 1 deletion crates/abq_cli/src/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,6 +40,7 @@ pub struct TestRunMetadata {
pub access_token: Option<abq_hosted::AccessToken>,
pub run_id: RunId,
pub record_telemetry: bool,
pub queue_location: QueueLocation,
}

pub async fn start_workers_standalone(
Expand Down Expand Up @@ -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!(
Expand Down
78 changes: 78 additions & 0 deletions crates/abq_cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 585f436

Please sign in to comment.