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

Commit 56276c2

Browse files
fix(tests): consistent wait for wasmcloud startup
Signed-off-by: Victor Adossi <[email protected]>
1 parent b511e88 commit 56276c2

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

tests/common.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,25 @@ impl TestWashInstance {
194194
};
195195

196196
// Wait until the host starts by checking the logs
197-
let mut tries: i32 = 30;
198-
let mut start_message_logs: String = String::new();
199-
loop {
200-
start_message_logs = read_to_string(wasmcloud_log.to_string().trim_matches('"'))
201-
.context("could not read log file output")?;
202-
if (start_message_logs.contains("Started wasmCloud OTP Host Runtime")) {
203-
break;
197+
let logs_path = String::from(wasmcloud_log.to_string().trim_matches('"'));
198+
tokio::time::timeout(Duration::from_secs(15), async move {
199+
loop {
200+
match tokio::fs::read_to_string(&logs_path).await {
201+
Ok(file_contents) => {
202+
if file_contents.contains("Started wasmCloud OTP Host Runtime") {
203+
// After wasmcloud says it's ready, it still requires some seconds to start up.
204+
tokio::time::sleep(Duration::from_secs(3)).await;
205+
break;
206+
}
207+
}
208+
_ => {
209+
println!("no host startup logs in output yet, waiting 1 second");
210+
tokio::time::sleep(Duration::from_secs(1)).await;
211+
}
212+
}
204213
}
205-
tries -= 1;
206-
assert!(tries >= 0);
207-
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
208-
}
209-
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
214+
})
215+
.await?;
210216

211217
Ok(TestWashInstance {
212218
test_dir,
@@ -430,3 +436,15 @@ pub(crate) async fn wait_for_nats_to_start() -> Result<()> {
430436
)
431437
.await
432438
}
439+
440+
/// Wait for no nats to be running by checking for process names
441+
#[allow(dead_code)]
442+
pub(crate) async fn wait_for_no_nats() -> Result<()> {
443+
wait_until_process_has_count(
444+
"nats-server",
445+
|v| v == 0,
446+
Duration::from_secs(10),
447+
Duration::from_millis(250),
448+
)
449+
.await
450+
}

tests/integration_dev.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use tokio::{process::Command, sync::RwLock, time::Duration};
88

99
mod common;
1010

11-
use crate::common::{init, start_nats, test_dir_with_subfolder, wait_for_no_hosts};
11+
use crate::common::{
12+
init, start_nats, test_dir_with_subfolder, wait_for_no_hosts, wait_for_no_nats,
13+
};
1214

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

100+
// Kill the nats instance
98101
nats.kill().await.map_err(|e| anyhow!(e))?;
102+
103+
wait_for_no_nats()
104+
.await
105+
.context("nats instance failed to exit cleanly (processes still left over")?;
106+
99107
Ok(())
100108
}

0 commit comments

Comments
 (0)