@@ -13,15 +13,15 @@ use indicatif::{ProgressBar, ProgressDrawTarget};
13
13
use mithril_common:: {
14
14
digesters:: DummyImmutablesDbBuilder ,
15
15
entities:: { Epoch , PartyId , ProtocolParameters } ,
16
- messages:: RegisterSignerMessage ,
16
+ messages:: { EpochSettingsMessage , RegisterSignerMessage } ,
17
17
test_utils:: { MithrilFixture , MithrilFixtureBuilder } ,
18
18
StdResult ,
19
19
} ;
20
20
21
21
use mithril_end_to_end:: { Aggregator , BftNode } ;
22
22
use reqwest:: StatusCode ;
23
23
use slog:: Level ;
24
- use slog_scope:: info;
24
+ use slog_scope:: { info, warn } ;
25
25
use thiserror:: Error ;
26
26
use tokio:: { select, task:: JoinSet , time:: sleep} ;
27
27
@@ -93,6 +93,50 @@ pub async fn wait_for_http_response(url: &str, timeout: Duration, message: &str)
93
93
}
94
94
}
95
95
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
+
96
140
pub fn write_stake_distribution (
97
141
mock_stake_distribution_file_path : & Path ,
98
142
signers_fixture : & MithrilFixture ,
@@ -127,7 +171,7 @@ pub struct MainOpts {
127
171
pub aggregator_dir : PathBuf ,
128
172
129
173
/// Number of concurrent signers
130
- #[ arg( long, default_value = "100 " ) ]
174
+ #[ arg( long, default_value = "20 " ) ]
131
175
pub num_signers : usize ,
132
176
133
177
/// Mithril technical Era
@@ -247,7 +291,7 @@ async fn main() -> StdResult<()> {
247
291
)
248
292
. unwrap ( ) ;
249
293
250
- write_epoch ( & mock_epoch_file_path, Epoch ( 26 ) ) ;
294
+ write_epoch ( & mock_epoch_file_path, Epoch ( 1 ) ) ;
251
295
write_stake_distribution ( & mock_stake_distribution_file_path, & signers_fixture) ;
252
296
253
297
aggregator. change_run_interval ( Duration :: from_secs ( 6 ) ) ;
@@ -304,6 +348,14 @@ async fn main() -> StdResult<()> {
304
348
305
349
assert_eq ! ( 0 , errors) ;
306
350
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
+
307
359
// ensure POSTing payload gives 200
308
360
aggregator. stop ( ) . await . unwrap ( ) ;
309
361
Ok ( ( ) )
0 commit comments