Skip to content

Commit 585f436

Browse files
authored
Adds a --local flag (#107)
1 parent 318ecb8 commit 585f436

File tree

6 files changed

+112
-10
lines changed

6 files changed

+112
-10
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/abq_cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "abq"
3-
version = "1.8.1"
3+
version = "1.9.0"
44
edition = "2021"
55

66
[dependencies]

crates/abq_cli/src/args.rs

+12
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ pub enum Command {
245245
.conflicts_with("tls_key"),
246246
)
247247
)]
248+
#[command(group(
249+
ArgGroup::new("local-queue-addr-exclusion") // don't allow both queue_addr and local params
250+
.multiple(false)
251+
.args(["local", "queue_addr"]),
252+
)
253+
)]
248254
Test {
249255
/// The number of the test worker connecting for a test suite run.
250256
///
@@ -274,6 +280,12 @@ pub enum Command {
274280
#[clap(long, required = false, env("RWX_ACCESS_TOKEN"))]
275281
access_token: Option<AccessToken>,
276282

283+
/// When specified, runs ABQ in local mode only.
284+
///
285+
/// Cannot be used with --queue-addr since a local queue will be used.
286+
#[clap(long, required = false, env("ABQ_LOCAL"), action)]
287+
local: bool,
288+
277289
/// Address of the queue where the test command will be sent.
278290
///
279291
/// Requires that abq workers be started as separate processes connected to the queue.

crates/abq_cli/src/main.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ async fn abq_main() -> anyhow::Result<ExitCode> {
386386
startup_timeout_seconds,
387387
test_strategy,
388388
inactivity_timeout_seconds,
389+
local,
389390
} => {
390391
let deprecations = DeprecationRecord::default();
391392
let stdout_preferences = StdoutPreferences::new(color);
@@ -400,14 +401,20 @@ async fn abq_main() -> anyhow::Result<ExitCode> {
400401
let tls_cert = read_opt_path_bytes(tls_cert)?;
401402
let tls_key = read_opt_path_bytes(tls_key)?;
402403

403-
let access_token = access_token.or_else(|| {
404-
let config = abq_config::read_abq_config(get_abq_config_filepath())?;
405-
Some(config.rwx_access_token)
406-
});
404+
let (access_token, api_config) = if local {
405+
(None, None)
406+
} else {
407+
let access_token = access_token.or_else(|| {
408+
let config = abq_config::read_abq_config(get_abq_config_filepath())?;
409+
Some(config.rwx_access_token)
410+
});
407411

408-
let api_config = match access_token.as_ref() {
409-
Some(access_token) => Some(get_config_from_api(access_token, &run_id).await?),
410-
None => None,
412+
let api_config = match access_token.as_ref() {
413+
Some(access_token) => Some(get_config_from_api(access_token, &run_id).await?),
414+
None => None,
415+
};
416+
417+
(access_token, api_config)
411418
};
412419

413420
let ResolvedConfig {
@@ -467,6 +474,7 @@ async fn abq_main() -> anyhow::Result<ExitCode> {
467474
access_token,
468475
run_id: run_id.clone(),
469476
record_telemetry: queue_location.is_remote(),
477+
queue_location,
470478
};
471479

472480
workers::start_workers_standalone(

crates/abq_cli/src/workers.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use signal_hook_tokio::Signals;
2424

2525
use crate::reporting::{build_reporters, ReporterKind, StdoutPreferences};
2626
use crate::workers::reporting::create_reporting_task;
27+
use crate::QueueLocation;
2728

2829
use self::reporting::ReportingTaskHandle;
2930

@@ -39,6 +40,7 @@ pub struct TestRunMetadata {
3940
pub access_token: Option<abq_hosted::AccessToken>,
4041
pub run_id: RunId,
4142
pub record_telemetry: bool,
43+
pub queue_location: QueueLocation,
4244
}
4345

4446
pub async fn start_workers_standalone(
@@ -188,7 +190,9 @@ async fn do_shutdown(
188190
.write_short_summary_lines(&mut stdout, ShortSummaryGrouping::Runner)
189191
.unwrap();
190192
println!("\n");
191-
if execution_mode == ExecutionMode::WriteNormal {
193+
if execution_mode == ExecutionMode::WriteNormal
194+
&& test_run_metadata.queue_location.is_remote()
195+
{
192196
println!("Run the following command to replay these tests locally:");
193197
println!("\n");
194198
println!(

crates/abq_cli/tests/cli.rs

+78
Original file line numberDiff line numberDiff line change
@@ -2816,6 +2816,84 @@ fn test_with_personal_access_token_and_auto_generated_run_id_uses_ephemeral_queu
28162816
);
28172817
}
28182818

2819+
#[test]
2820+
#[with_protocol_version]
2821+
#[serial]
2822+
fn test_with_access_token_and_local_uses_ephemeral_queue() {
2823+
let name = "test_with_access_token_and_local_uses_ephemeral_queue";
2824+
let conf = CSConfigOptions {
2825+
use_auth_token: true,
2826+
tls: false,
2827+
};
2828+
2829+
let server = Server::new();
2830+
let access_token = test_access_token();
2831+
2832+
let manifest = vec![TestOrGroup::test(Test::new(
2833+
proto,
2834+
"some_test",
2835+
[],
2836+
Default::default(),
2837+
))];
2838+
let manifest = ManifestMessage::new(Manifest::new(manifest, Default::default()));
2839+
2840+
let proto = AbqProtocolVersion::V0_2.get_supported_witness().unwrap();
2841+
2842+
let simulation = [
2843+
Connect,
2844+
OpaqueWrite(pack(legal_spawned_message(proto))),
2845+
IfGenerateManifest {
2846+
then_do: vec![OpaqueWrite(pack(&manifest))],
2847+
else_do: vec![
2848+
OpaqueRead,
2849+
OpaqueWrite(pack(InitSuccessMessage::new(proto))),
2850+
OpaqueRead,
2851+
OpaqueWrite(pack(RawTestResultMessage::fake(proto))),
2852+
],
2853+
},
2854+
Exit(0),
2855+
];
2856+
let packed = pack_msgs_to_disk(simulation);
2857+
2858+
let test_args = {
2859+
let simulator = native_runner_simulation_bin();
2860+
let simfile_path = packed.path.display().to_string();
2861+
let args = vec![
2862+
format!("test"),
2863+
format!("--worker=1"),
2864+
format!("-n=1"),
2865+
format!("--local"),
2866+
];
2867+
let mut args = conf.extend_args_for_client(args);
2868+
args.extend([s!("--"), simulator, simfile_path]);
2869+
args
2870+
};
2871+
2872+
let CmdOutput {
2873+
stdout,
2874+
stderr,
2875+
exit_status,
2876+
} = Abq::new(format!("{name}_test"))
2877+
.args(test_args)
2878+
.env([
2879+
("ABQ_API", &server.url()),
2880+
("RWX_ACCESS_TOKEN", &access_token.to_string()),
2881+
])
2882+
.run();
2883+
assert!(
2884+
exit_status.success(),
2885+
"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
2886+
);
2887+
assert!(
2888+
stdout.contains("1 tests, 0 failures"),
2889+
"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
2890+
);
2891+
assert!(
2892+
!stdout.contains("Run the following command to replay these tests locally"),
2893+
"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
2894+
);
2895+
}
2896+
28192897
#[test]
28202898
#[with_protocol_version]
28212899
#[serial]

0 commit comments

Comments
 (0)