Skip to content

Commit 691ac19

Browse files
committed
Add a wait for the next epoch in load test
1 parent f122261 commit 691ac19

File tree

1 file changed

+56
-4
lines changed
  • mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator

1 file changed

+56
-4
lines changed

mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use indicatif::{ProgressBar, ProgressDrawTarget};
1313
use mithril_common::{
1414
digesters::DummyImmutablesDbBuilder,
1515
entities::{Epoch, PartyId, ProtocolParameters},
16-
messages::RegisterSignerMessage,
16+
messages::{EpochSettingsMessage, RegisterSignerMessage},
1717
test_utils::{MithrilFixture, MithrilFixtureBuilder},
1818
StdResult,
1919
};
2020

2121
use mithril_end_to_end::{Aggregator, BftNode};
2222
use reqwest::StatusCode;
2323
use slog::Level;
24-
use slog_scope::info;
24+
use slog_scope::{info, warn};
2525
use thiserror::Error;
2626
use tokio::{select, task::JoinSet, time::sleep};
2727

@@ -93,6 +93,50 @@ pub async fn wait_for_http_response(url: &str, timeout: Duration, message: &str)
9393
}
9494
}
9595

96+
/// Wait for a given epoch in the epoch settings until timeout
97+
pub async fn wait_for_epoch_settings_at_epoch(
98+
url: &str,
99+
timeout: Duration,
100+
epoch: Epoch,
101+
) -> StdResult<()> {
102+
let progress_bar =
103+
ProgressBar::new_spinner().with_message(format!("Waiting for epoch {epoch}"));
104+
let spinner = async move {
105+
loop {
106+
progress_bar.tick();
107+
sleep(Duration::from_millis(50)).await;
108+
}
109+
};
110+
let probe = async move {
111+
while let Ok(response) = reqwest::get(url).await {
112+
match response.status() {
113+
StatusCode::OK => {
114+
let epoch_settings = response.json::<EpochSettingsMessage>().await.unwrap();
115+
116+
if epoch_settings.epoch >= epoch {
117+
break;
118+
}
119+
sleep(Duration::from_millis(300)).await
120+
}
121+
s if s.is_server_error() => {
122+
warn!(
123+
"Server error while waiting for the Aggregator, http code: {}",
124+
s
125+
);
126+
break;
127+
}
128+
_ => sleep(Duration::from_millis(300)).await,
129+
}
130+
}
131+
};
132+
133+
select! {
134+
_ = spinner => Err(String::new().into()),
135+
_ = sleep(timeout) => Err(format!("Aggregator did not get a response after {timeout:?} from '{url}'").into()),
136+
_ = probe => Ok(())
137+
}
138+
}
139+
96140
pub fn write_stake_distribution(
97141
mock_stake_distribution_file_path: &Path,
98142
signers_fixture: &MithrilFixture,
@@ -127,7 +171,7 @@ pub struct MainOpts {
127171
pub aggregator_dir: PathBuf,
128172

129173
/// Number of concurrent signers
130-
#[arg(long, default_value = "100")]
174+
#[arg(long, default_value = "20")]
131175
pub num_signers: usize,
132176

133177
/// Mithril technical Era
@@ -247,7 +291,7 @@ async fn main() -> StdResult<()> {
247291
)
248292
.unwrap();
249293

250-
write_epoch(&mock_epoch_file_path, Epoch(26));
294+
write_epoch(&mock_epoch_file_path, Epoch(1));
251295
write_stake_distribution(&mock_stake_distribution_file_path, &signers_fixture);
252296

253297
aggregator.change_run_interval(Duration::from_secs(6));
@@ -304,6 +348,14 @@ async fn main() -> StdResult<()> {
304348

305349
assert_eq!(0, errors);
306350

351+
write_epoch(&mock_epoch_file_path, Epoch(2));
352+
wait_for_epoch_settings_at_epoch(
353+
&format!("{}/epoch-settings", aggregator.endpoint()),
354+
Duration::from_secs(10),
355+
Epoch(2),
356+
)
357+
.await?;
358+
307359
// ensure POSTing payload gives 200
308360
aggregator.stop().await.unwrap();
309361
Ok(())

0 commit comments

Comments
 (0)