From 790d35793ddbcef969aa9e54eb23a668fe03a23c Mon Sep 17 00:00:00 2001 From: Brooks Townsend Date: Fri, 9 Jun 2023 10:26:38 -0400 Subject: [PATCH] Adjusted tests with new burrito behavior Signed-off-by: Brooks Townsend un-re-de-comment integration build Signed-off-by: Brooks Townsend removed test debugs Signed-off-by: Brooks Townsend removed moar printlns Signed-off-by: Brooks Townsend cfg idk Signed-off-by: Brooks Townsend sleepy Signed-off-by: Brooks Townsend sleepy Signed-off-by: Brooks Townsend --- Makefile | 2 +- crates/wash-lib/src/registry.rs | 1 + src/up/mod.rs | 80 +++++++++++++++++++++++---------- tests/common.rs | 12 ++++- tests/integration_inspect.rs | 2 +- tests/integration_par.rs | 2 +- tests/integration_up.rs | 33 +++++++++++--- 7 files changed, 97 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index f924ff3ff..3dfc3eb31 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ build-watch: ## Continuously build the project test: ## Run unit test suite @$(CARGO) nextest run $(CARGO_TEST_TARGET) --no-fail-fast --bin wash - @$(CARGO) nextest run $(CARGO_TEST_TARGET) --no-fail-fast -p wash-lib + @$(CARGO) nextest run $(CARGO_TEST_TARGET) --no-fail-fast -p wash-lib --features=cli test-wash-ci: @$(CARGO) nextest run --profile ci --workspace --bin wash diff --git a/crates/wash-lib/src/registry.rs b/crates/wash-lib/src/registry.rs index b9babac04..e450cd8fb 100644 --- a/crates/wash-lib/src/registry.rs +++ b/crates/wash-lib/src/registry.rs @@ -6,6 +6,7 @@ use std::{ }; use anyhow::{anyhow, bail, Result}; +#[cfg(feature = "cli")] use clap::{Parser, Subcommand}; use oci_distribution::manifest::OciImageManifest; use oci_distribution::{ diff --git a/src/up/mod.rs b/src/up/mod.rs index faeb922f5..2e274d784 100644 --- a/src/up/mod.rs +++ b/src/up/mod.rs @@ -287,10 +287,45 @@ pub(crate) async fn handle_up(cmd: UpCommand, output_kind: OutputKind) -> Result // Find an open port for the host, and if the user specified a port, ensure it's open let host_port = ensure_open_port(cmd.wasmcloud_opts.dashboard_port).await?; + // Ensure we use the open dashboard port and the supplied NATS host/port if no overrides were supplied + let wasmcloud_opts = WasmcloudOpts { + dashboard_port: Some(host_port), + ctl_host: Some( + cmd.wasmcloud_opts + .ctl_host + .unwrap_or_else(|| cmd.nats_opts.nats_host.to_owned()), + ), + ctl_port: Some( + cmd.wasmcloud_opts + .ctl_port + .unwrap_or(cmd.nats_opts.nats_port), + ), + rpc_host: Some( + cmd.wasmcloud_opts + .rpc_host + .unwrap_or_else(|| cmd.nats_opts.nats_host.to_owned()), + ), + rpc_port: Some( + cmd.wasmcloud_opts + .rpc_port + .unwrap_or(cmd.nats_opts.nats_port), + ), + prov_rpc_host: Some( + cmd.wasmcloud_opts + .prov_rpc_host + .unwrap_or_else(|| cmd.nats_opts.nats_host.to_owned()), + ), + prov_rpc_port: Some( + cmd.wasmcloud_opts + .prov_rpc_port + .unwrap_or(cmd.nats_opts.nats_port), + ), + ..cmd.wasmcloud_opts + }; // Capture listen address to keep the value after the nats_opts are moved let nats_listen_address = format!("{}:{}", cmd.nats_opts.nats_host, cmd.nats_opts.nats_port); - let nats_client = nats_client_from_wasmcloud_opts(&cmd.wasmcloud_opts).await; + let nats_client = nats_client_from_wasmcloud_opts(&wasmcloud_opts).await; let nats_opts = cmd.nats_opts.clone(); // Avoid downloading + starting NATS if the user already runs their own server and we can connect. @@ -298,6 +333,7 @@ pub(crate) async fn handle_up(cmd: UpCommand, output_kind: OutputKind) -> Result // Ignore connect_only if this server has a remote and credsfile as we have to start a leafnode in that scenario let supplied_remote_credentials = cmd.nats_opts.nats_remote_url.is_some() && cmd.nats_opts.nats_credsfile.is_some(); + let nats_bin = if should_run_nats || supplied_remote_credentials { // Download NATS if not already installed spinner.update_spinner_message(" Downloading NATS ...".to_string()); @@ -313,10 +349,10 @@ pub(crate) async fn handle_up(cmd: UpCommand, output_kind: OutputKind) -> Result // Based on the options provided for wasmCloud, form a client connection to NATS. // If this fails, we should return early since wasmCloud wouldn't be able to connect either - nats_client_from_wasmcloud_opts(&cmd.wasmcloud_opts).await?; + nats_client_from_wasmcloud_opts(&wasmcloud_opts).await?; let wadm_process = if !cmd.wadm_opts.disable_wadm - && !is_wadm_running(&nats_opts, &cmd.wasmcloud_opts.lattice_prefix) + && !is_wadm_running(&nats_opts, &wasmcloud_opts.lattice_prefix) .await .unwrap_or(false) { @@ -357,19 +393,17 @@ pub(crate) async fn handle_up(cmd: UpCommand, output_kind: OutputKind) -> Result // Download wasmCloud if not already installed let wasmcloud_executable = if !cmd.wasmcloud_opts.start_only { spinner.update_spinner_message(" Downloading wasmCloud ...".to_string()); - ensure_wasmcloud(&cmd.wasmcloud_opts.wasmcloud_version, &install_dir).await? + ensure_wasmcloud(&wasmcloud_opts.wasmcloud_version, &install_dir).await? + } else if let Some(wasmcloud_bin) = + find_wasmcloud_binary(&install_dir, &wasmcloud_opts.wasmcloud_version).await + { + wasmcloud_bin } else { - if let Some(wasmcloud_bin) = - find_wasmcloud_binary(&install_dir, &cmd.wasmcloud_opts.wasmcloud_version).await - { - wasmcloud_bin - } else { - // Ensure we clean up the NATS server if we can't start wasmCloud - if nats_bin.is_some() { - stop_nats(install_dir).await?; - } - return Err(anyhow!("wasmCloud was not installed, exiting without downloading as --wasmcloud-start-only was set")); + // Ensure we clean up the NATS server if we can't start wasmCloud + if nats_bin.is_some() { + stop_nats(install_dir).await?; } + return Err(anyhow!("wasmCloud was not installed, exiting without downloading as --wasmcloud-start-only was set")); }; // Redirect output (which is on stderr) to a log file in detached mode, or use the terminal @@ -384,12 +418,8 @@ pub(crate) async fn handle_up(cmd: UpCommand, output_kind: OutputKind) -> Result } else { Stdio::piped() }; - let version = cmd.wasmcloud_opts.wasmcloud_version.clone(); - // Ensure we use the open dashboard port - let wasmcloud_opts = WasmcloudOpts { - dashboard_port: Some(host_port), - ..cmd.wasmcloud_opts - }; + let version = wasmcloud_opts.wasmcloud_version.clone(); + let host_env = configure_host_env(nats_opts, wasmcloud_opts).await; let wasmcloud_child = match start_wasmcloud_host( &wasmcloud_executable, @@ -579,10 +609,12 @@ async fn is_wadm_running(nats_opts: &NatsOpts, lattice_prefix: &str) -> Result) -> Result { if let Some(port) = supplied_port { - tokio::net::TcpStream::connect((LOCALHOST, port)) - .await - .map(|_tcp_stream| port) - .map_err(|e| anyhow!(e)) + match tokio::net::TcpStream::connect((LOCALHOST, port)).await { + Ok(_tcp_stream) => Err(anyhow!( + "Supplied host port {port} already has a process listening" + )), + Err(_e) => Ok(port), + } } else { let start_port = DEFAULT_DASHBOARD_PORT.parse().unwrap_or(4000); let end_port = start_port + 1000; diff --git a/tests/common.rs b/tests/common.rs index bb1e4ef3f..9ac571a44 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -105,7 +105,13 @@ impl Drop for TestWashInstance { let kill_cmd = kill_cmd.to_string(); let (_wash, down) = kill_cmd.trim_matches('"').split_once(' ').unwrap(); wash() - .args(vec![down]) + .args(vec![ + down, + "--host-id", + &self.host_id, + "--ctl-port", + &self.nats_port.to_string(), + ]) .output() .expect("Could not spawn wash down process"); @@ -171,6 +177,7 @@ impl TestWashInstance { .context("up command failed to complete")?; assert!(status.success()); + let out = read_to_string(&log_path).context("could not read output of wash up")?; let (kill_cmd, wasmcloud_log) = match serde_json::from_str::(&out) { @@ -179,7 +186,7 @@ impl TestWashInstance { }; // Wait until the host starts by checking the logs - let mut tries = 30; + let mut tries: i32 = 30; let mut start_message_logs: String = String::new(); loop { start_message_logs = read_to_string(wasmcloud_log.to_string().trim_matches('"')) @@ -191,6 +198,7 @@ impl TestWashInstance { assert!(tries >= 0); tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; } + tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; Ok(TestWashInstance { test_dir, diff --git a/tests/integration_inspect.rs b/tests/integration_inspect.rs index 1e8269af7..a6dc7a546 100644 --- a/tests/integration_inspect.rs +++ b/tests/integration_inspect.rs @@ -219,5 +219,5 @@ fn integration_inspect_cached() { assert!(!remote_inspect_no_cache.status.success()); - remove_file(http_client_cache_path).unwrap(); + let _ = remove_file(http_client_cache_path); } diff --git a/tests/integration_par.rs b/tests/integration_par.rs index 8fdbe25da..018a045af 100644 --- a/tests/integration_par.rs +++ b/tests/integration_par.rs @@ -345,5 +345,5 @@ fn integration_par_inspect_cached() { assert!(!remote_inspect_no_cache.status.success()); - remove_file(http_client_cache_path).unwrap(); + let _ = remove_file(http_client_cache_path); } diff --git a/tests/integration_up.rs b/tests/integration_up.rs index a9b67e7ee..9db83adb8 100644 --- a/tests/integration_up.rs +++ b/tests/integration_up.rs @@ -61,7 +61,13 @@ async fn integration_up_can_start_wasmcloud_and_actor_serial() -> Result<()> { let mut tries = 30; while tries >= 0 { let output = Command::new(env!("CARGO_BIN_EXE_wash")) - .args(["ctl", "get", "inventory", &host_seed.public_key()]) + .args([ + "get", + "inventory", + &host_seed.public_key(), + "--ctl-port", + "5893", + ]) .kill_on_drop(true) .output() .await @@ -71,13 +77,13 @@ async fn integration_up_can_start_wasmcloud_and_actor_serial() -> Result<()> { assert!(tries >= 0); tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; } else { + tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; break; } } let start_echo = Command::new(env!("CARGO_BIN_EXE_wash")) .args([ - "ctl", "start", "actor", "wasmcloud.azurecr.io/echo:0.3.4", @@ -100,6 +106,7 @@ async fn integration_up_can_start_wasmcloud_and_actor_serial() -> Result<()> { String::from_utf8_lossy(&start_echo.stderr) ); + tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; let kill_cmd = kill_cmd.to_string(); let (_wash, down) = kill_cmd.trim_matches('"').split_once(' ').unwrap(); Command::new(env!("CARGO_BIN_EXE_wash")) @@ -120,16 +127,21 @@ async fn integration_up_can_stop_detached_host_serial() -> Result<()> { let path = dir.join("washup.log"); let stdout = std::fs::File::create(&path).expect("could not create log file for wash up test"); + // sleep for 10 seconds + tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; + + let host_seed = nkeys::KeyPair::new_server(); + let mut up_cmd = Command::new(env!("CARGO_BIN_EXE_wash")) .args([ "up", "--nats-port", "5894", - "--dashboard-port", - "5001", "-o", "json", "--detached", + "--host-seed", + &host_seed.seed().expect("Should have a seed for the host"), ]) .kill_on_drop(true) .stdout(stdout) @@ -160,11 +172,18 @@ async fn integration_up_can_stop_detached_host_serial() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; } + tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await; + let kill_cmd = kill_cmd.to_string(); let (_wash, down) = kill_cmd.trim_matches('"').split_once(' ').unwrap(); Command::new(env!("CARGO_BIN_EXE_wash")) - .args(vec![down]) - .kill_on_drop(true) + .args(vec![ + down, + "--ctl-port", + "5894", + "--host-id", + &host_seed.public_key(), + ]) .output() .await .context("Could not spawn wash down process")?; @@ -239,6 +258,8 @@ async fn integration_up_doesnt_kill_unowned_nats_serial() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; } + tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; + let kill_cmd = kill_cmd.to_string(); let (_wash, down) = kill_cmd.trim_matches('"').split_once(' ').unwrap(); Command::new(env!("CARGO_BIN_EXE_wash"))