Skip to content

Commit

Permalink
Revert "Remove autopilot e2e readiness check"
Browse files Browse the repository at this point in the history
This reverts commit fb8dad3.
  • Loading branch information
squadgazzz committed Sep 4, 2024
1 parent fb8dad3 commit db3a1b5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/e2e/src/setup/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
},
reqwest::{Client, StatusCode, Url},
sqlx::Connection,
std::time::Duration,
std::{ops::DerefMut, time::Duration},
};

pub const API_HOST: &str = "http://127.0.0.1:8080";
Expand Down Expand Up @@ -146,6 +146,7 @@ impl<'a> Services<'a> {

let args = autopilot::arguments::Arguments::try_parse_from(args).unwrap();
tokio::task::spawn(autopilot::run(args));
self.wait_until_autopilot_ready().await;
}

/// Start the api service in a background tasks.
Expand Down Expand Up @@ -300,6 +301,21 @@ impl<'a> Services<'a> {
.expect("waiting for API timed out");
}

async fn wait_until_autopilot_ready(&self) {
let is_up = || async {
let mut db = self.db.acquire().await.unwrap();
const QUERY: &str = "SELECT COUNT(*) FROM auctions";
let count: i64 = sqlx::query_scalar(QUERY)
.fetch_one(db.deref_mut())
.await
.unwrap();
count > 0
};
wait_for_condition(TIMEOUT, is_up)
.await
.expect("waiting for autopilot timed out");
}

pub async fn get_auction(&self) -> dto::AuctionWithId {
let response = self
.http
Expand Down

0 comments on commit db3a1b5

Please sign in to comment.