Skip to content

Commit e5e639c

Browse files
committed
Better logs for rust e2e tests:
* always output logs if the test failed * show a frame containing the process name when dumping logs * write process logs synchronously so there's no logs from other sources stuck between dumped process logs.
1 parent dbb67f5 commit e5e639c

File tree

7 files changed

+38
-21
lines changed

7 files changed

+38
-21
lines changed

mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,24 @@ impl Spec {
1515
Self { infrastructure }
1616
}
1717

18-
pub async fn run(&mut self) -> Result<(), Box<dyn Error>> {
18+
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
1919
let aggregator_endpoint = self.infrastructure.aggregator().endpoint();
2020

2121
wait_for_pending_certificate(&aggregator_endpoint).await?;
2222
let digest = assert_node_producing_snapshot(&aggregator_endpoint).await?;
2323
let certificate_hash =
2424
assert_signer_is_signing_snapshot(&aggregator_endpoint, &digest).await?;
2525
assert_is_creating_certificate(&aggregator_endpoint, &certificate_hash).await?;
26-
assert_client_can_verify_snapshot(self.infrastructure.client_mut(), &digest).await?;
26+
27+
let mut client = self.infrastructure.build_client()?;
28+
assert_client_can_verify_snapshot(&mut client, &digest).await?;
29+
30+
Ok(())
31+
}
32+
33+
pub async fn dump_processes_logs(&mut self) -> Result<(), String> {
34+
self.infrastructure.aggregator_mut().dump_logs().await?;
35+
self.infrastructure.signer_mut().dump_logs().await?;
2736

2837
Ok(())
2938
}

mithril-test-lab/mithril-end-to-end/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
4343
match spec.run().await {
4444
Ok(_) => Ok(()),
4545
Err(error) => {
46+
spec.dump_processes_logs().await?;
4647
error!("Mithril End to End test failed: {}", error);
47-
spec.dump_logs_of_failed_processes().await?;
4848
Err(error)
4949
}
5050
}

mithril-test-lab/mithril-end-to-end/src/mithril/aggregator.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ impl Aggregator {
6161
self.process = Some(self.command.start(&[]));
6262
}
6363

64+
pub async fn dump_logs(&self) -> Result<(), String> {
65+
self.command.dump_logs_to_stdout().await
66+
}
67+
6468
pub async fn dump_logs_if_crashed(&mut self) -> Result<(), String> {
6569
match self.process.as_mut() {
6670
Some(child) => match child.try_wait() {
6771
Ok(Some(status)) => {
6872
if !status.success() {
69-
self.command.dump_logs_to_stdout().await?;
73+
self.dump_logs().await?;
7074
}
7175
Ok(())
7276
}

mithril-test-lab/mithril-end-to-end/src/mithril/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Client {
4949

5050
Err(match status.code() {
5151
Some(c) => format!("mithril-signer exited with code: {}", c),
52-
None => "mithril-signer was terminated with a signal".to_string(),
52+
None => "mithril-client was terminated with a signal".to_string(),
5353
})
5454
}
5555
}
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::{Aggregator, Client, Signer};
22
use std::borrow::BorrowMut;
3-
use std::path::Path;
3+
use std::path::{Path, PathBuf};
44

55
pub struct MithrilInfrastructure {
6+
work_dir: PathBuf,
7+
bin_dir: PathBuf,
68
aggregator: Aggregator,
7-
client: Client,
89
signer: Signer,
910
}
1011

@@ -16,15 +17,15 @@ impl MithrilInfrastructure {
1617
bin_dir: &Path,
1718
) -> Result<Self, String> {
1819
let mut aggregator = Aggregator::new(server_port, db_dir, work_dir, bin_dir)?;
19-
let client = Client::new(aggregator.endpoint(), work_dir, bin_dir)?;
2020
let mut signer = Signer::new(aggregator.endpoint(), db_dir, work_dir, bin_dir)?;
2121

2222
aggregator.start();
2323
signer.start();
2424

2525
Ok(Self {
26+
work_dir: work_dir.to_path_buf(),
27+
bin_dir: bin_dir.to_path_buf(),
2628
aggregator,
27-
client,
2829
signer,
2930
})
3031
}
@@ -37,19 +38,15 @@ impl MithrilInfrastructure {
3738
self.aggregator.borrow_mut()
3839
}
3940

40-
pub fn client(&self) -> &Client {
41-
&self.client
42-
}
43-
44-
pub fn client_mut(&mut self) -> &mut Client {
45-
self.client.borrow_mut()
46-
}
47-
4841
pub fn signer(&self) -> &Signer {
4942
&self.signer
5043
}
5144

5245
pub fn signer_mut(&mut self) -> &mut Signer {
5346
self.signer.borrow_mut()
5447
}
48+
49+
pub fn build_client(&self) -> Result<Client, String> {
50+
Client::new(self.aggregator.endpoint(), &self.work_dir, &self.bin_dir)
51+
}
5552
}

mithril-test-lab/mithril-end-to-end/src/mithril/mithril_command.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use slog_scope::info;
22
use std::collections::HashMap;
3+
use std::io::Write;
34
use std::path::{Path, PathBuf};
4-
use tokio::io::AsyncWriteExt;
55
use tokio::process::{Child, Command};
66

77
#[derive(Debug)]
@@ -95,9 +95,12 @@ impl MithrilCommand {
9595
)
9696
})?;
9797

98-
tokio::io::stdout()
98+
println!("{:-^100}", "");
99+
println!("{:^30}", format!("{} LOGS:", self.name.to_uppercase()));
100+
println!("{:-^100}", "");
101+
102+
std::io::stdout()
99103
.write_all(&buffer)
100-
.await
101104
.map_err(|e| format!("failed to dump {} logs: {}", &self.name, e))?;
102105

103106
Ok(())

mithril-test-lab/mithril-end-to-end/src/mithril/signer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ impl Signer {
3737
self.process = Some(self.command.start(&[]));
3838
}
3939

40+
pub async fn dump_logs(&self) -> Result<(), String> {
41+
self.command.dump_logs_to_stdout().await
42+
}
43+
4044
pub async fn dump_logs_if_crashed(&mut self) -> Result<(), String> {
4145
match self.process.as_mut() {
4246
Some(child) => match child.try_wait() {
4347
Ok(Some(status)) => {
4448
if !status.success() {
45-
self.command.dump_logs_to_stdout().await?;
49+
self.dump_logs().await?;
4650
}
4751
Ok(())
4852
}

0 commit comments

Comments
 (0)