Skip to content

Commit

Permalink
Merge pull request #3211 from Zeegomo/fix-leadership-logs
Browse files Browse the repository at this point in the history
Fix leadership_logs_parent_hash_is_correct
  • Loading branch information
zeegomo committed Apr 13, 2021
2 parents ff03eb5 + 00ea705 commit afddbdf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::JormungandrError;
use super::{starter::StartupError, JormungandrError};
use crate::common::jcli::{JCli, JCliCommand};
use assert_fs::TempDir;
use chain_impl_mockchain::fee::LinearFee;
Expand All @@ -23,6 +23,7 @@ use std::process::Child;
use std::process::Stdio;
use std::str::FromStr;
use std::thread::panicking;
use std::time::{Duration, Instant};

pub enum StartupVerificationMode {
Log,
Expand Down Expand Up @@ -69,7 +70,36 @@ impl JormungandrProcess {
}
}

pub fn status(&self, strategy: &StartupVerificationMode) -> Status {
pub fn wait_for_bootstrap(
&self,
verification_mode: &StartupVerificationMode,
timeout: Duration,
) -> Result<(), StartupError> {
let start = Instant::now();
loop {
if start.elapsed() > timeout {
return Err(StartupError::Timeout {
timeout: timeout.as_secs(),
log_content: self.logger.get_log_content(),
});
}
match self.status(&verification_mode) {
Status::Running => {
println!("jormungandr is up");
return Ok(());
}
Status::Stopped(err) => {
println!("attempt stopped due to error signal recieved");
println!("Raw log:\n {}", self.logger.get_log_content());
return Err(StartupError::JormungandrError(err));
}
Status::Starting => {}
}
std::thread::sleep(Duration::from_secs(2));
}
}

fn status(&self, strategy: &StartupVerificationMode) -> Status {
let port_occupied_msgs = ["error 87", "error 98", "panicked at 'Box<Any>'"];
if self.logger.contains_any_of(&port_occupied_msgs) {
return Status::Stopped(JormungandrError::PortAlreadyInUse);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod commands;
pub use commands::{get_command, CommandBuilder};

use super::process::{StartupVerificationMode, Status};
use super::process::StartupVerificationMode;
use super::ConfigurationBuilder;
use super::JormungandrError;
use crate::common::{configuration::get_jormungandr_app, jormungandr::process::JormungandrProcess};
Expand Down Expand Up @@ -384,7 +384,11 @@ where
self.temp_dir.take(),
self.starter.alias.clone(),
);
match (self.verify_is_up(&mut jormungandr), self.starter.on_fail) {
match (
jormungandr
.wait_for_bootstrap(&self.starter.verification_mode, self.starter.timeout),
self.starter.on_fail,
) {
(Ok(()), _) => {
return Ok(jormungandr);
}
Expand Down Expand Up @@ -425,29 +429,4 @@ where
self.temp_dir = jormungandr.steal_temp_dir();
}
}

fn verify_is_up(&self, process: &mut JormungandrProcess) -> Result<(), StartupError> {
let start = Instant::now();
loop {
if start.elapsed() > self.starter.timeout {
return Err(StartupError::Timeout {
timeout: self.starter.timeout.as_secs(),
log_content: process.logger.get_log_content(),
});
}
match process.status(&self.starter.verification_mode) {
Status::Running => {
println!("jormungandr is up");
return Ok(());
}
Status::Stopped(err) => {
println!("attempt stopped due to error signal recieved");
println!("Raw log:\n {}", process.logger.get_log_content());
return Err(StartupError::JormungandrError(err));
}
Status::Starting => {}
}
process_utils::sleep(self.starter.sleep);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::common::{jcli::JCli, jormungandr::ConfigurationBuilder, startup};
use crate::common::{
jcli::JCli,
jormungandr::{ConfigurationBuilder, StartupVerificationMode},
startup,
};
use jormungandr_lib::interfaces::LeadershipLogStatus;
use jortestkit::process::sleep;
use std::time::Duration;

#[test]
pub fn test_leadership_logs_parent_hash_is_correct() {
Expand All @@ -9,7 +13,9 @@ pub fn test_leadership_logs_parent_hash_is_correct() {
let (jormungandr, _) =
startup::start_stake_pool(&[faucet], &[], &mut ConfigurationBuilder::new()).unwrap();

sleep(5);
jormungandr
.wait_for_bootstrap(&StartupVerificationMode::Rest, Duration::from_secs(10))
.unwrap();

let leadership_logs = jcli.rest().v0().leadership_log(jormungandr.rest_uri());

Expand Down

0 comments on commit afddbdf

Please sign in to comment.