Skip to content

Commit

Permalink
Start Mithril devnet once Cardano devnet is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Feb 8, 2023
1 parent 35dde3f commit d68f1fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mithril-test-lab/mithril-end-to-end/src/devnet/runner.rs
@@ -1,3 +1,4 @@
use mithril_common::digesters::ImmutableFile;
use mithril_common::entities::PartyId;
use slog_scope::info;
use std::fs;
Expand Down Expand Up @@ -156,6 +157,16 @@ impl Devnet {
}
}

pub fn is_ready(&self) -> Result<bool, String> {
let topology = self.topology();
let bft_node = topology
.bft_nodes
.first()
.ok_or("no bft node available".to_string())?;

Ok(ImmutableFile::list_completed_in_dir(&bft_node.db_path).is_ok())
}

pub async fn run(&self) -> Result<(), String> {
let run_script = "start-cardano.sh";
let run_script_path = self.artifacts_dir.join(run_script);
Expand Down
11 changes: 11 additions & 0 deletions mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs
@@ -1,10 +1,12 @@
use crate::{attempt, utils::AttemptResult};
use crate::{Aggregator, Client, Devnet, Signer, DEVNET_MAGIC_ID};
use mithril_common::chain_observer::{CardanoCliChainObserver, CardanoCliRunner};
use mithril_common::entities::ProtocolParameters;
use mithril_common::CardanoNetwork;
use std::borrow::BorrowMut;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;

pub struct MithrilInfrastructure {
work_dir: PathBuf,
Expand All @@ -23,6 +25,15 @@ impl MithrilInfrastructure {
bin_dir: &Path,
) -> Result<Self, String> {
devnet.run().await?;

match attempt!(1000, Duration::from_secs(30), {
Ok(devnet.is_ready().ok().map(|_| ()))
}) {
AttemptResult::Ok(_) => Ok(()),
AttemptResult::Err(error) => Err(error),
AttemptResult::Timeout() => Err("Timeout exhausted for devnet to be ready".to_string()),
}?;

let devnet_topology = devnet.topology();
let bft_node = devnet_topology
.bft_nodes
Expand Down

0 comments on commit d68f1fe

Please sign in to comment.