Skip to content

Commit

Permalink
Wait for rbuilder running before running integration test (#160)
Browse files Browse the repository at this point in the history
## 📝 Summary

The new integration test introduced in #143 requires the rbuilder to be
running to work. However, the playground setup was not waiting for it.
This PR fixes that. It adds a loop after the rbuilder creation that
checks in the output log for a specific log "RPC server job: started"
that signals that the builder is running and the test can start.

## 💡 Motivation and Context

<!--- (Optional) Why is this change required? What problem does it
solve? Remove this section if not applicable. -->

---

## ✅ I have completed the following steps:

* [x] Run `make lint`
* [x] Run `make test`
* [x] Added tests (if applicable)
  • Loading branch information
ferranbt authored Aug 28, 2024
1 parent 7cb7f31 commit 7f7a5ae
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions crates/rbuilder/src/integration/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::{
path::PathBuf,
process::{Child, Command},
str::FromStr,
time::SystemTime,
thread,
time::{Instant, SystemTime},
};
use time::{format_description, OffsetDateTime};
use url::Url;
Expand All @@ -26,6 +27,7 @@ pub enum PlaygroundError {
BinaryNotFound,
SetupError,
IntegrationPathNotFound,
Timeout,
}

pub struct Playground {
Expand Down Expand Up @@ -77,7 +79,7 @@ impl Playground {
let mut log_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
log_path.push(format!("../../integration_logs/{}.log", name));

let log = open_log_file(log_path).map_err(|_| PlaygroundError::SetupError)?;
let log = open_log_file(log_path.clone()).map_err(|_| PlaygroundError::SetupError)?;
let stdout = log.try_clone().map_err(|_| PlaygroundError::SetupError)?;
let stderr = log.try_clone().map_err(|_| PlaygroundError::SetupError)?;

Expand All @@ -94,6 +96,26 @@ impl Playground {
},
}?;

let start = Instant::now();
loop {
if start.elapsed().as_secs() > 10 {
return Err(PlaygroundError::Timeout);
}

// from the log file, check if the server has started
// by checking if the string "RPC server job: started" is present
let mut file = File::open(&log_path).map_err(|_| PlaygroundError::SetupError)?;
let mut contents = String::new();
file.read_to_string(&mut contents)
.map_err(|_| PlaygroundError::SetupError)?;

if contents.contains("RPC server job: started") {
break;
}

thread::sleep(std::time::Duration::from_millis(100));
}

Ok(Self { builder })
}

Expand Down

0 comments on commit 7f7a5ae

Please sign in to comment.