Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Adjusted tests with new burrito behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <[email protected]>

un-re-de-comment integration build

Signed-off-by: Brooks Townsend <[email protected]>

removed test debugs

Signed-off-by: Brooks Townsend <[email protected]>

removed moar printlns

Signed-off-by: Brooks Townsend <[email protected]>

cfg idk

Signed-off-by: Brooks Townsend <[email protected]>

sleepy

Signed-off-by: Brooks Townsend <[email protected]>

sleepy

Signed-off-by: Brooks Townsend <[email protected]>
  • Loading branch information
brooksmtownsend committed Jun 12, 2023
1 parent 0b28548 commit 790d357
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/wash-lib/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
80 changes: 56 additions & 24 deletions src/up/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,53 @@ 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.
let should_run_nats = !cmd.nats_opts.connect_only && nats_client.is_err();
// 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());
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -579,10 +609,12 @@ async fn is_wadm_running(nats_opts: &NatsOpts, lattice_prefix: &str) -> Result<b
/// `supplied_port` - The port supplied by the user so we can check if it's open
async fn ensure_open_port(supplied_port: Option<u16>) -> Result<u16> {
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;
Expand Down
12 changes: 10 additions & 2 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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::<serde_json::Value>(&out) {
Expand All @@ -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('"'))
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion tests/integration_par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
33 changes: 27 additions & 6 deletions tests/integration_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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"))
Expand All @@ -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)
Expand Down Expand Up @@ -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")?;
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 790d357

Please sign in to comment.