Skip to content

Commit

Permalink
implement ServicesBuilder in e2e services module
Browse files Browse the repository at this point in the history
  • Loading branch information
devanoneth committed Jan 24, 2024
1 parent b08a15b commit d6d62d6
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions crates/e2e/src/setup/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@ pub const VERSION_ENDPOINT: &str = "/api/v1/version";
pub const SOLVER_COMPETITION_ENDPOINT: &str = "/api/v1/solver_competition";
const LOCAL_DB_URL: &str = "postgresql://";

pub struct ServicesBuilder {
timeout: Duration,
}

impl Default for ServicesBuilder {
fn default() -> Self {
Self::new()
}
}

impl ServicesBuilder {
pub fn new() -> Self {
Self {
timeout: Duration::from_secs(10),
}
}

pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}

pub async fn build(self, contracts: &Contracts) -> Services {
Services {
contracts,
http: Client::builder().timeout(self.timeout).build().unwrap(),
db: sqlx::PgPool::connect(LOCAL_DB_URL).await.unwrap(),
}
}
}

/// Wrapper over offchain services.
/// Exposes various utility methods for tests.
pub struct Services<'a> {
Expand All @@ -51,12 +82,8 @@ impl<'a> Services<'a> {
}
}

pub async fn new_with_timeout(contracts: &'a Contracts, timeout: Duration) -> Services<'a> {
Self {
contracts,
http: Client::builder().timeout(timeout).build().unwrap(),
db: sqlx::PgPool::connect(LOCAL_DB_URL).await.unwrap(),
}
pub fn builder() -> ServicesBuilder {
ServicesBuilder::new()
}

fn api_autopilot_arguments() -> impl Iterator<Item = String> {
Expand Down

0 comments on commit d6d62d6

Please sign in to comment.