Skip to content

Commit d76dc5f

Browse files
authored
Merge pull request #1994 from input-output-hk/djo/e2e/better-folder-structure
Better folder structure for End to End test
2 parents b9b227f + 4bdc047 commit d76dc5f

File tree

7 files changed

+89
-24
lines changed

7 files changed

+89
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-test-lab/mithril-end-to-end/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-end-to-end"
3-
version = "0.4.37"
3+
version = "0.4.38"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
documentation = { workspace = true }

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::{
1111
fs,
1212
path::{Path, PathBuf},
1313
sync::Arc,
14-
thread::sleep,
1514
time::Duration,
1615
};
1716
use tokio_util::sync::CancellationToken;
@@ -174,6 +173,11 @@ async fn main() -> StdResult<()> {
174173
work_dir.canonicalize().unwrap()
175174
}
176175
};
176+
let artifacts_dir = {
177+
let path = work_dir.join("artifacts");
178+
fs::create_dir(&path).expect("Artifacts dir creation failure");
179+
path
180+
};
177181
let run_only_mode = args.run_only;
178182
let use_p2p_network_mode = args.use_p2p_network;
179183
let use_p2p_passive_relays = args.use_p2p_passive_relays;
@@ -193,6 +197,7 @@ async fn main() -> StdResult<()> {
193197
let mut infrastructure = MithrilInfrastructure::start(&MithrilInfrastructureConfig {
194198
server_port,
195199
devnet: devnet.clone(),
200+
artifacts_dir,
196201
work_dir,
197202
bin_dir: args.bin_directory,
198203
cardano_node_version: args.cardano_node_version,
@@ -224,33 +229,39 @@ async fn main() -> StdResult<()> {
224229
};
225230

226231
match runner {
227-
Ok(_) if run_only_mode => run_until_cancelled(devnet).await,
232+
Ok(_) if run_only_mode => run_until_cancelled(infrastructure, devnet).await,
228233
Ok(_) => {
234+
infrastructure.stop_nodes().await?;
229235
devnet.stop().await?;
230236
Ok(())
231237
}
232238
Err(error) => {
233239
let has_written_logs = infrastructure.tail_logs(40).await;
234240
error!("Mithril End to End test in failed: {}", error);
241+
infrastructure.stop_nodes().await?;
235242
devnet.stop().await?;
236243
has_written_logs?;
237244
Err(error)
238245
}
239246
}
240247
}
241248

242-
async fn run_until_cancelled(devnet: Devnet) -> StdResult<()> {
249+
async fn run_until_cancelled(
250+
mut mithril_infrastructure: MithrilInfrastructure,
251+
devnet: Devnet,
252+
) -> StdResult<()> {
243253
let cancellation_token = CancellationToken::new();
244254
let cloned_token = cancellation_token.clone();
245255

246256
tokio::select! {
247257
_ = tokio::spawn(async move {
248258
while !cloned_token.is_cancelled() {
249259
info!("Mithril end to end is running and will remain active until manually stopped...");
250-
sleep(Duration::from_secs(5));
260+
tokio::time::sleep(Duration::from_secs(5)).await;
251261
}
252262
}) => {}
253263
_ = tokio::signal::ctrl_c() => {
264+
mithril_infrastructure.stop_nodes().await?;
254265
cancellation_token.cancel();
255266
devnet.stop().await?;
256267
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
use anyhow::{anyhow, Context};
77
use mithril_common::era::SupportedEra;
88
use mithril_common::{entities, StdResult};
9+
use slog_scope::info;
910
use std::cmp;
1011
use std::collections::HashMap;
1112
use std::path::{Path, PathBuf};
@@ -18,6 +19,7 @@ pub struct AggregatorConfig<'a> {
1819
pub pool_node: &'a PoolNode,
1920
pub cardano_cli_path: &'a Path,
2021
pub work_dir: &'a Path,
22+
pub artifacts_dir: &'a Path,
2123
pub bin_dir: &'a Path,
2224
pub cardano_node_version: &'a str,
2325
pub mithril_run_interval: u32,
@@ -62,6 +64,10 @@ impl Aggregator {
6264
("URL_SNAPSHOT_MANIFEST", ""),
6365
("SNAPSHOT_STORE_TYPE", "local"),
6466
("SNAPSHOT_UPLOADER_TYPE", "local"),
67+
(
68+
"SNAPSHOT_DIRECTORY",
69+
aggregator_config.artifacts_dir.to_str().unwrap(),
70+
),
6571
("NETWORK_MAGIC", &magic_id),
6672
("DATA_STORES_DIRECTORY", "./stores/aggregator"),
6773
(
@@ -139,8 +145,11 @@ impl Aggregator {
139145
}
140146

141147
pub async fn bootstrap_genesis(&mut self) -> StdResult<()> {
142-
let exit_status = self
143-
.command
148+
// Clone the command so we can alter it without affecting the original
149+
let mut command = self.command.clone();
150+
command.set_log_name("mithril-aggregator-genesis-bootstrap");
151+
152+
let exit_status = command
144153
.start(&["genesis".to_string(), "bootstrap".to_string()])?
145154
.wait()
146155
.await
@@ -162,10 +171,12 @@ impl Aggregator {
162171

163172
pub async fn stop(&mut self) -> StdResult<()> {
164173
if let Some(process) = self.process.as_mut() {
174+
info!("Stopping aggregator");
165175
process
166176
.kill()
167177
.await
168178
.with_context(|| "Could not kill aggregator")?;
179+
self.process = None;
169180
}
170181
Ok(())
171182
}

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

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
assertions, Aggregator, AggregatorConfig, Client, Devnet, PoolNode, RelayAggregator,
3-
RelayPassive, RelaySigner, Signer, DEVNET_MAGIC_ID,
4-
};
1+
use anyhow::Context;
52
use mithril_common::chain_observer::{ChainObserver, PallasChainObserver};
63
use mithril_common::entities::{Epoch, PartyId, ProtocolParameters};
74
use mithril_common::{CardanoNetwork, StdResult};
@@ -11,12 +8,18 @@ use std::fs;
118
use std::path::PathBuf;
129
use std::sync::Arc;
1310

11+
use crate::{
12+
assertions, Aggregator, AggregatorConfig, Client, Devnet, PoolNode, RelayAggregator,
13+
RelayPassive, RelaySigner, Signer, DEVNET_MAGIC_ID,
14+
};
15+
1416
use super::signer::SignerConfig;
1517

1618
pub struct MithrilInfrastructureConfig {
1719
pub server_port: u64,
1820
pub devnet: Devnet,
1921
pub work_dir: PathBuf,
22+
pub artifacts_dir: PathBuf,
2023
pub bin_dir: PathBuf,
2124
pub cardano_node_version: String,
2225
pub mithril_run_interval: u32,
@@ -30,7 +33,7 @@ pub struct MithrilInfrastructureConfig {
3033
}
3134

3235
pub struct MithrilInfrastructure {
33-
work_dir: PathBuf,
36+
artifacts_dir: PathBuf,
3437
bin_dir: PathBuf,
3538
devnet: Devnet,
3639
aggregator: Aggregator,
@@ -77,8 +80,8 @@ impl MithrilInfrastructure {
7780
));
7881

7982
Ok(Self {
80-
work_dir: config.work_dir.to_path_buf(),
8183
bin_dir: config.bin_dir.to_path_buf(),
84+
artifacts_dir: config.artifacts_dir.to_path_buf(),
8285
devnet: config.devnet.clone(),
8386
aggregator,
8487
signers,
@@ -137,11 +140,22 @@ impl MithrilInfrastructure {
137140
pool_node: &PoolNode,
138141
chain_observer_type: &str,
139142
) -> StdResult<Aggregator> {
143+
let aggregator_artifacts_directory = config.artifacts_dir.join("mithril-aggregator");
144+
if !aggregator_artifacts_directory.exists() {
145+
fs::create_dir_all(&aggregator_artifacts_directory).with_context(|| {
146+
format!(
147+
"Could not create artifacts directory '{}'",
148+
aggregator_artifacts_directory.display()
149+
)
150+
})?;
151+
}
152+
140153
let mut aggregator = Aggregator::new(&AggregatorConfig {
141154
server_port: config.server_port,
142155
pool_node,
143156
cardano_cli_path: &config.devnet.cardano_cli_path(),
144157
work_dir: &config.work_dir,
158+
artifacts_dir: &aggregator_artifacts_directory,
145159
bin_dir: &config.bin_dir,
146160
cardano_node_version: &config.cardano_node_version,
147161
mithril_run_interval: config.mithril_run_interval,
@@ -275,6 +289,18 @@ impl MithrilInfrastructure {
275289
Ok(signers)
276290
}
277291

292+
pub async fn stop_nodes(&mut self) -> StdResult<()> {
293+
// Note: The aggregator should be stopped *last* since signers depends on it
294+
info!("Stopping Mithril infrastructure");
295+
for signer in self.signers.as_mut_slice() {
296+
signer.stop().await?;
297+
}
298+
299+
self.aggregator.stop().await?;
300+
301+
Ok(())
302+
}
303+
278304
pub fn devnet(&self) -> &Devnet {
279305
&self.devnet
280306
}
@@ -312,15 +338,16 @@ impl MithrilInfrastructure {
312338
}
313339

314340
pub fn build_client(&self) -> StdResult<Client> {
315-
let work_dir = if self.use_era_specific_work_dir {
316-
let era_work_dir = self.work_dir.join(format!("era.{}", self.current_era));
317-
if !era_work_dir.exists() {
318-
fs::create_dir(&era_work_dir)?;
341+
let work_dir = {
342+
let mut artifacts_dir = self.artifacts_dir.join("mithril-client");
343+
if self.use_era_specific_work_dir {
344+
artifacts_dir = artifacts_dir.join(format!("era.{}", self.current_era));
345+
}
346+
if !artifacts_dir.exists() {
347+
fs::create_dir_all(&artifacts_dir)?;
319348
}
320349

321-
era_work_dir
322-
} else {
323-
self.work_dir.clone()
350+
artifacts_dir
324351
};
325352

326353
Client::new(self.aggregator.endpoint(), &work_dir, &self.bin_dir)

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use crate::devnet::PoolNode;
22
use crate::utils::MithrilCommand;
33
use crate::{DEVNET_MAGIC_ID, ERA_MARKERS_VERIFICATION_KEY};
4+
use anyhow::Context;
45
use mithril_common::entities::PartyId;
56
use mithril_common::StdResult;
7+
use slog_scope::info;
68
use std::collections::HashMap;
79
use std::path::Path;
810
use tokio::process::Child;
@@ -24,6 +26,7 @@ pub struct SignerConfig<'a> {
2426

2527
#[derive(Debug)]
2628
pub struct Signer {
29+
name: String,
2730
party_id: PartyId,
2831
command: MithrilCommand,
2932
process: Option<Child>,
@@ -103,11 +106,11 @@ impl Signer {
103106
env,
104107
&args,
105108
)?;
106-
command.set_log_name(
107-
format!("mithril-signer-{}-{party_id}", signer_config.signer_number).as_str(),
108-
);
109+
let name = format!("mithril-signer-{}-{party_id}", signer_config.signer_number);
110+
command.set_log_name(&name);
109111

110112
Ok(Self {
113+
name,
111114
party_id,
112115
command,
113116
process: None,
@@ -119,6 +122,18 @@ impl Signer {
119122
Ok(())
120123
}
121124

125+
pub async fn stop(&mut self) -> StdResult<()> {
126+
if let Some(process) = self.process.as_mut() {
127+
let name = self.name.as_str();
128+
info!("Stopping {name}");
129+
process
130+
.kill()
131+
.await
132+
.with_context(|| "Could not kill signer")?;
133+
self.process = None;
134+
}
135+
Ok(())
136+
}
122137
pub async fn tail_logs(&self, number_of_line: u64) -> StdResult<()> {
123138
self.command
124139
.tail_logs(

mithril-test-lab/mithril-end-to-end/src/stress_test/aggregator_helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub async fn bootstrap_aggregator(
2323
pool_node: &args.pool_node,
2424
cardano_cli_path: &args.cardano_cli_path,
2525
work_dir: &args.work_dir,
26+
artifacts_dir: &args.work_dir,
2627
bin_dir: &args.bin_dir,
2728
cardano_node_version: "1.2.3",
2829
mithril_run_interval: 1000,

0 commit comments

Comments
 (0)