Skip to content

Commit

Permalink
review: panic in wait_for_geth_node_ready if Deth node is not ready a…
Browse files Browse the repository at this point in the history
…fter several attempts
  • Loading branch information
laruh committed May 17, 2024
1 parent ff92a20 commit a2c47f8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions mm2src/mm2_main/tests/docker_tests_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern crate serde_json;
#[cfg(test)] extern crate ser_error_derive;
#[cfg(test)] extern crate test;

use common::custom_futures::timeout::FutureTimerExt;
use std::io::{BufRead, BufReader};
use std::process::Command;
use std::time::Duration;
Expand Down Expand Up @@ -105,21 +106,23 @@ pub fn docker_tests_runner(tests: &[&TestDescAndFn]) {
fn wait_for_geth_node_ready() {
let mut attempts = 0;
loop {
if attempts >= 10 {
println!("Failed to connect to Geth node after several attempts.");
break;
if attempts >= 5 {
panic!("Failed to connect to Geth node after several attempts.");
}
match block_on(GETH_WEB3.eth().block_number()) {
Ok(block_number) => {
match block_on(GETH_WEB3.eth().block_number().timeout(Duration::from_secs(6))) {
Ok(Ok(block_number)) => {
println!("Geth node is ready, latest block number: {:?}", block_number);
break;
},
Err(e) => {
Ok(Err(e)) => {
println!("Failed to connect to Geth node: {:?}, retrying...", e);
attempts += 1;
thread::sleep(Duration::from_secs(1));
},
Err(_) => {
println!("Connection to Geth node timed out, retrying...");
},
}
attempts += 1;
thread::sleep(Duration::from_secs(1));
}
}

Expand Down

0 comments on commit a2c47f8

Please sign in to comment.