Skip to content

Commit

Permalink
Move tail_logs in infrastructure & update run-only option
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed Jul 12, 2023
1 parent c34667a commit b4e55c9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 70 deletions.
14 changes: 1 addition & 13 deletions mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use mithril_common::chain_observer::ChainObserver;
use std::error::Error;

pub struct Spec {
infrastructure: MithrilInfrastructure,
pub infrastructure: MithrilInfrastructure,
}

impl Spec {
Expand Down Expand Up @@ -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(())
}
}
29 changes: 23 additions & 6 deletions mithril-test-lab/mithril-end-to-end/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -97,13 +98,29 @@ async fn main() -> Result<(), Box<dyn Error>> {
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?;
Expand All @@ -120,7 +137,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
55 changes: 4 additions & 51 deletions mithril-test-lab/mithril-end-to-end/src/run_only.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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 {
pub fn new(infrastructure: MithrilInfrastructure) -> Self {
Self { infrastructure }
}

pub async fn run(&mut self) -> Result<(), Box<dyn Error>> {
pub async fn start(&mut self) -> Result<(), Box<dyn Error>> {
let aggregator_endpoint = self.infrastructure.aggregator().endpoint();
assertions::wait_for_enough_immutable(self.infrastructure.aggregator().db_directory())
.await?;
Expand All @@ -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,
Expand All @@ -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(())
}
}

0 comments on commit b4e55c9

Please sign in to comment.