diff --git a/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs b/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs index 81a2ec2f039..514f0b4ce44 100644 --- a/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs +++ b/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs @@ -4,7 +4,7 @@ use mithril_common::chain_observer::ChainObserver; use std::error::Error; pub struct Spec { - infrastructure: MithrilInfrastructure, + pub infrastructure: MithrilInfrastructure, } impl Spec { @@ -109,16 +109,4 @@ impl Spec { Ok(()) } - - pub async fn tail_logs(&self, number_of_line: u64) -> Result<(), String> { - self.infrastructure - .aggregator() - .tail_logs(number_of_line) - .await?; - for signer in self.infrastructure.signers() { - signer.tail_logs(number_of_line).await?; - } - - Ok(()) - } } diff --git a/mithril-test-lab/mithril-end-to-end/src/main.rs b/mithril-test-lab/mithril-end-to-end/src/main.rs index bd4104f1e36..77fe31b9702 100644 --- a/mithril-test-lab/mithril-end-to-end/src/main.rs +++ b/mithril-test-lab/mithril-end-to-end/src/main.rs @@ -2,11 +2,12 @@ use clap::Parser; use mithril_end_to_end::{Devnet, MithrilInfrastructure}; use mithril_end_to_end::{RunOnly, Spec}; use slog::{Drain, Logger}; -use slog_scope::error; -use std::error::Error; -use std::fs; +use slog_scope::{crit, error, info}; use std::path::{Path, PathBuf}; use std::sync::Arc; +use std::{error::Error, fs}; +use std::{thread::sleep, time::Duration}; +use tokio::task::JoinSet; /// Tests args #[derive(Parser, Debug, Clone)] @@ -97,13 +98,29 @@ async fn main() -> Result<(), Box> { true => { let mut run_only = RunOnly::new(infrastructure); - match run_only.run().await { + match run_only.start().await { Ok(_) => { + let mut join_set = JoinSet::new(); + join_set.spawn(async move { + loop { + info!("Mithril end to end is running and will remain active until manually stopped..."); + sleep(Duration::from_secs(5)); + } + }); + join_set + .spawn(async { tokio::signal::ctrl_c().await.map_err(|e| e.to_string()) }); + + if let Err(e) = join_set.join_next().await.unwrap()? { + crit!("A critical error occurred: {e}"); + } + devnet.stop().await?; + join_set.shutdown().await; + Ok(()) } Err(error) => { - let has_written_logs = run_only.tail_logs(20).await; + let has_written_logs = run_only.infrastructure.tail_logs(20).await; error!("Mithril End to End test in run-only mode failed: {}", error); devnet.stop().await?; has_written_logs?; @@ -120,7 +137,7 @@ async fn main() -> Result<(), Box> { Ok(()) } Err(error) => { - let has_written_logs = spec.tail_logs(20).await; + let has_written_logs = spec.infrastructure.tail_logs(20).await; error!("Mithril End to End test failed: {}", error); devnet.stop().await?; has_written_logs?; diff --git a/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs b/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs index 72a836e7b1a..f7e34246451 100644 --- a/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs +++ b/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs @@ -118,4 +118,13 @@ impl MithrilInfrastructure { pub fn run_only_mode(&self) -> bool { self.run_only_mode } + + pub async fn tail_logs(&self, number_of_line: u64) -> Result<(), String> { + self.aggregator().tail_logs(number_of_line).await?; + for signer in self.signers() { + signer.tail_logs(number_of_line).await?; + } + + Ok(()) + } } diff --git a/mithril-test-lab/mithril-end-to-end/src/run_only.rs b/mithril-test-lab/mithril-end-to-end/src/run_only.rs index 4262c035a11..888d715df2f 100644 --- a/mithril-test-lab/mithril-end-to-end/src/run_only.rs +++ b/mithril-test-lab/mithril-end-to-end/src/run_only.rs @@ -1,11 +1,10 @@ use crate::assertions; use crate::MithrilInfrastructure; use mithril_common::chain_observer::ChainObserver; -use slog_scope::info; -use std::{error::Error, thread::sleep, time::Duration}; +use std::error::Error; pub struct RunOnly { - infrastructure: MithrilInfrastructure, + pub infrastructure: MithrilInfrastructure, } impl RunOnly { @@ -13,7 +12,7 @@ impl RunOnly { Self { infrastructure } } - pub async fn run(&mut self) -> Result<(), Box> { + pub async fn start(&mut self) -> Result<(), Box> { let aggregator_endpoint = self.infrastructure.aggregator().endpoint(); assertions::wait_for_enough_immutable(self.infrastructure.aggregator().db_directory()) .await?; @@ -25,7 +24,7 @@ impl RunOnly { .unwrap_or_default(); // Wait 3 epochs after start epoch for the aggregator to be able to bootstrap a genesis certificate - let mut target_epoch = start_epoch + 3; + let target_epoch = start_epoch + 3; assertions::wait_for_target_epoch( self.infrastructure.chain_observer(), target_epoch, @@ -36,52 +35,6 @@ impl RunOnly { assertions::bootstrap_genesis_certificate(self.infrastructure.aggregator_mut()).await?; assertions::wait_for_epoch_settings(&aggregator_endpoint).await?; - // Wait 2 epochs before changing stake distribution, so that we use at least one original stake distribution - target_epoch += 2; - assertions::wait_for_target_epoch( - self.infrastructure.chain_observer(), - target_epoch, - "epoch after which the stake distribution will change".to_string(), - ) - .await?; - assertions::delegate_stakes_to_pools(self.infrastructure.devnet()).await?; - - // Wait 2 epochs before changing protocol parameters - target_epoch += 2; - assertions::wait_for_target_epoch( - self.infrastructure.chain_observer(), - target_epoch, - "epoch after which the protocol parameters will change".to_string(), - ) - .await?; - assertions::update_protocol_parameters(self.infrastructure.aggregator_mut()).await?; - - // Wait 5 epochs after protocol parameters update, so that we make sure that we use new protocol parameters as well as new stake distribution a few times - target_epoch += 5; - assertions::wait_for_target_epoch( - self.infrastructure.chain_observer(), - target_epoch, - "epoch after which the certificate chain will be long enough to catch most common troubles with stake distribution and protocol parameters".to_string(), - ) - .await?; - - loop { - info!("Mithril end to end is running and will remain active until manually stopped..."); - sleep(Duration::from_secs(5)); - } - - Ok(()) - } - - pub async fn tail_logs(&self, number_of_line: u64) -> Result<(), String> { - self.infrastructure - .aggregator() - .tail_logs(number_of_line) - .await?; - for signer in self.infrastructure.signers() { - signer.tail_logs(number_of_line).await?; - } - Ok(()) } }