Skip to content

Commit

Permalink
feat: Dispatch messages before and after start of the agents (#4604)
Browse files Browse the repository at this point in the history
### Description

Dispatch messages before and after start of the agents so that we test
both forward and backward looking sequence based indexers.

### Related issues

- Successfully scrape Cosmos chains in e2e test #3355

### Backward compatibility

Yes

### Testing

- E2E Cosmos Test
- Manual check on E2E Cosmos Test logs

---------

Co-authored-by: Danil Nemirovsky <4614623+ameten@users.noreply.github.com>
  • Loading branch information
ameten and ameten authored Oct 3, 2024
1 parent 3c8c688 commit 2287142
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 deletions rust/main/utils/run-locally/src/cosmos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@ fn run_locally() {
.unwrap()
);

// count all the dispatched messages
let mut dispatched_messages = 0;

// dispatch the first batch of messages (before agents start)
dispatched_messages += dispatch(&osmosisd, linker, &nodes);

let config_dir = tempdir().unwrap();

// export agent config
Expand Down Expand Up @@ -525,9 +531,51 @@ fn run_locally() {

let starting_relayer_balance: f64 = agent_balance_sum(hpl_rly_metrics_port).unwrap();

// dispatch messages
let mut dispatched_messages = 0;
// dispatch the second batch of messages (after agents start)
dispatched_messages += dispatch(&osmosisd, linker, &nodes);

let _stack = CosmosHyperlaneStack {
validators: hpl_val.into_iter().map(|v| v.join()).collect(),
relayer: hpl_rly.join(),
scraper: hpl_scr.join(),
postgres,
};

// Mostly copy-pasta from `rust/main/utils/run-locally/src/main.rs`
// TODO: refactor to share code
let loop_start = Instant::now();
let mut failure_occurred = false;
loop {
// look for the end condition.
if termination_invariants_met(
hpl_rly_metrics_port,
hpl_scr_metrics_port,
dispatched_messages,
starting_relayer_balance,
)
.unwrap_or(false)
{
// end condition reached successfully
break;
} else if (Instant::now() - loop_start).as_secs() > TIMEOUT_SECS {
// we ran out of time
log!("timeout reached before message submission was confirmed");
failure_occurred = true;
break;
}

sleep(Duration::from_secs(5));
}

if failure_occurred {
panic!("E2E tests failed");
} else {
log!("E2E tests passed");
}
}

fn dispatch(osmosisd: &Path, linker: &str, nodes: &[CosmosNetwork]) -> u32 {
let mut dispatched_messages = 0;
for node in nodes.iter() {
let targets = nodes
.iter()
Expand All @@ -545,7 +593,7 @@ fn run_locally() {
for target in targets {
dispatched_messages += 1;
let cli = OsmosisCLI::new(
osmosisd.clone(),
osmosisd.to_path_buf(),
node.launch_resp.home_path.to_str().unwrap(),
);

Expand Down Expand Up @@ -574,44 +622,7 @@ fn run_locally() {
}
}

let _stack = CosmosHyperlaneStack {
validators: hpl_val.into_iter().map(|v| v.join()).collect(),
relayer: hpl_rly.join(),
scraper: hpl_scr.join(),
postgres,
};

// Mostly copy-pasta from `rust/main/utils/run-locally/src/main.rs`
// TODO: refactor to share code
let loop_start = Instant::now();
let mut failure_occurred = false;
loop {
// look for the end condition.
if termination_invariants_met(
hpl_rly_metrics_port,
hpl_scr_metrics_port,
dispatched_messages,
starting_relayer_balance,
)
.unwrap_or(false)
{
// end condition reached successfully
break;
} else if (Instant::now() - loop_start).as_secs() > TIMEOUT_SECS {
// we ran out of time
log!("timeout reached before message submission was confirmed");
failure_occurred = true;
break;
}

sleep(Duration::from_secs(5));
}

if failure_occurred {
panic!("E2E tests failed");
} else {
log!("E2E tests passed");
}
dispatched_messages
}

fn termination_invariants_met(
Expand Down

0 comments on commit 2287142

Please sign in to comment.