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

Commit

Permalink
fix(tests): consistent wait for wasmcloud startup
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
  • Loading branch information
vados-cosmonic committed Jul 7, 2023
1 parent b511e88 commit 56276c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
42 changes: 30 additions & 12 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,25 @@ impl TestWashInstance {
};

// Wait until the host starts by checking the logs
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('"'))
.context("could not read log file output")?;
if (start_message_logs.contains("Started wasmCloud OTP Host Runtime")) {
break;
let logs_path = String::from(wasmcloud_log.to_string().trim_matches('"'));
tokio::time::timeout(Duration::from_secs(15), async move {
loop {
match tokio::fs::read_to_string(&logs_path).await {
Ok(file_contents) => {
if file_contents.contains("Started wasmCloud OTP Host Runtime") {
// After wasmcloud says it's ready, it still requires some seconds to start up.
tokio::time::sleep(Duration::from_secs(3)).await;
break;
}
}
_ => {
println!("no host startup logs in output yet, waiting 1 second");
tokio::time::sleep(Duration::from_secs(1)).await;
}
}
}
tries -= 1;
assert!(tries >= 0);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
})
.await?;

Ok(TestWashInstance {
test_dir,
Expand Down Expand Up @@ -430,3 +436,15 @@ pub(crate) async fn wait_for_nats_to_start() -> Result<()> {
)
.await
}

/// Wait for no nats to be running by checking for process names
#[allow(dead_code)]
pub(crate) async fn wait_for_no_nats() -> Result<()> {
wait_until_process_has_count(
"nats-server",
|v| v == 0,
Duration::from_secs(10),
Duration::from_millis(250),
)
.await
}
10 changes: 9 additions & 1 deletion tests/integration_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use tokio::{process::Command, sync::RwLock, time::Duration};

mod common;

use crate::common::{init, start_nats, test_dir_with_subfolder, wait_for_no_hosts};
use crate::common::{
init, start_nats, test_dir_with_subfolder, wait_for_no_hosts, wait_for_no_nats,
};

#[tokio::test]
#[serial]
Expand Down Expand Up @@ -95,6 +97,12 @@ async fn integration_dev_hello_actor_serial() -> Result<()> {
.await
.context("wasmcloud instance failed to exit cleanly (processes still left over)")?;

// Kill the nats instance
nats.kill().await.map_err(|e| anyhow!(e))?;

wait_for_no_nats()
.await
.context("nats instance failed to exit cleanly (processes still left over")?;

Ok(())
}

0 comments on commit 56276c2

Please sign in to comment.