@@ -194,19 +194,25 @@ impl TestWashInstance {
194
194
} ;
195
195
196
196
// 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
+ }
204
213
}
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 ?;
210
216
211
217
Ok ( TestWashInstance {
212
218
test_dir,
@@ -430,3 +436,15 @@ pub(crate) async fn wait_for_nats_to_start() -> Result<()> {
430
436
)
431
437
. await
432
438
}
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
+ }
0 commit comments