Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,25 @@ impl RunLoop {
tracing::debug!("no current auction");
return None;
};

if auction.orders.is_empty() {
// Updating liveness probe to not report unhealthy due to this optimization
self.probes.liveness.auction();
tracing::debug!("skipping empty auction");
return None;
}

let id = self
.persistence
.get_next_auction_id()
.await
.inspect_err(|err| tracing::error!(?err, "failed to get next auction id"))
.ok()?;
Metrics::auction(id);

// always update the auction because the tests use this as a readiness probe
Metrics::auction(id);
self.persistence.replace_current_auction_in_db(id, &auction);
self.persistence.upload_auction_to_s3(id, &auction);

if auction.orders.is_empty() {
// Updating liveness probe to not report unhealthy due to this optimization
self.probes.liveness.auction();
tracing::debug!("skipping empty auction");
return None;
}
Some(domain::Auction {
id,
block: auction.block,
Expand Down
31 changes: 2 additions & 29 deletions crates/e2e/src/setup/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use {
},
reqwest::{Client, StatusCode, Url},
sqlx::Connection,
std::{ops::DerefMut, str::FromStr, time::Duration},
std::{str::FromStr, time::Duration},
tokio::task::JoinHandle,
};

Expand Down Expand Up @@ -92,7 +92,6 @@ impl ServicesBuilder {
contracts: onchain_components.contracts(),
http: Client::builder().timeout(self.timeout).build().unwrap(),
db: sqlx::PgPool::connect(LOCAL_DB_URL).await.unwrap(),
web3: onchain_components.web3(),
}
}
}
Expand All @@ -109,7 +108,6 @@ pub struct Services<'a> {
contracts: &'a Contracts,
http: Client,
db: Db,
web3: &'a Web3,
}

impl<'a> Services<'a> {
Expand All @@ -121,7 +119,6 @@ impl<'a> Services<'a> {
.build()
.unwrap(),
db: sqlx::PgPool::connect(LOCAL_DB_URL).await.unwrap(),
web3: onchain_components.web3(),
}
}

Expand Down Expand Up @@ -185,10 +182,7 @@ impl<'a> Services<'a> {
..config
};

let join_handle = tokio::task::spawn(autopilot::run(config, control));
self.wait_until_autopilot_ready().await;

join_handle
tokio::task::spawn(autopilot::run(config, control))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Removing the readiness check wait_until_autopilot_ready() introduces a potential race condition in E2E tests. While the autopilot might be fast to start, CI environments are often resource-constrained and slower, which can lead to flaky tests if they attempt to place orders or verify state before the autopilot's background tasks (like cache warming and event listeners) are fully initialized. Instead of removing the synchronization entirely, consider implementing a readiness check that doesn't rely on non-empty auctions, such as polling the autopilot's metrics endpoint or checking for the startup probe to be set.

References
  1. For integration tests, prioritize CI stability by ensuring robust synchronization and handling potential environment-related delays gracefully.

}

/// Start the autopilot service in a background task.
Expand Down Expand Up @@ -422,22 +416,6 @@ 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();
self.mint_block().await;
count > 0
};
wait_for_condition(TIMEOUT, is_up)
.await
.expect("waiting for autopilot timed out");
}

/// Fetches the current auction. Don't use this as a synchronization
/// mechanism in tests because that is prone to race conditions
/// which would make tests flaky.
Expand Down Expand Up @@ -924,11 +902,6 @@ impl<'a> Services<'a> {
pub fn db(&self) -> &Db {
&self.db
}

async fn mint_block(&self) {
tracing::info!("mining block");
self.web3.provider.evm_mine(None).await.unwrap();
}
}

pub async fn clear_database() {
Expand Down
Loading