Skip to content

Commit

Permalink
fix: Fix bug in test harness for unstable network (#4980)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <[email protected]>
  • Loading branch information
SamHSmith authored Aug 29, 2024
1 parent 6f339ab commit be22388
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/iroha2-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
name: executor.wasm
path: ${{ env.DOCKER_COMPOSE_PATH }}
- name: Run tests
run: mold --run cargo test --no-default-features --no-fail-fast -p iroha extra_functional
run: mold --run cargo test --no-default-features --no-fail-fast -p iroha extra_functional -- --test-threads=1

# Run the job to check that the docker containers are properly buildable
pr-generator-build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn register_new_peer() -> Result<()> {
.1
.submit_blocking(register_peer)?;
peer_clients.push((&new_peer, Client::test(&new_peer.api_address)));
thread::sleep(pipeline_time * 2); // Wait for some time to allow peers to connect
thread::sleep(pipeline_time * 2 * 20); // Wait for some time to allow peers to connect

check_status(&peer_clients, 2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ fn unstable_network(
let mut account_has_quantity = Numeric::ZERO;

let mut rng = rand::thread_rng();
let freezers = {
let mut freezers = network.get_freeze_status_handles();
freezers.remove(0); // remove genesis peer
freezers
};
let freezers = network.get_freeze_status_handles();

//When
for _i in 0..n_transactions {
Expand Down
25 changes: 8 additions & 17 deletions core/test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use iroha_primitives::{
unique_vec::UniqueVec,
};
use irohad::Iroha;
use rand::{prelude::SliceRandom, seq::IteratorRandom, thread_rng};
use rand::{prelude::SliceRandom, thread_rng};
use tempfile::TempDir;
use test_samples::{ALICE_ID, ALICE_KEYPAIR, PEER_KEYPAIR, SAMPLE_GENESIS_ACCOUNT_KEYPAIR};
use tokio::{
Expand Down Expand Up @@ -281,12 +281,7 @@ impl NetworkBuilder {
/// Returns network and client for connecting to it.
pub async fn create_with_client(self) -> (Network, Client) {
let network = self.create().await;
let client = Client::test(
&Network::peers(&network)
.choose(&mut thread_rng())
.unwrap()
.api_address,
);
let client = Client::test(&network.first_peer.api_address);
(network, client)
}

Expand All @@ -306,10 +301,11 @@ enum PeerInfo {
}

impl Network {
/// Collect the freeze handles from all the peers in the network.
/// Collect the freeze handles from all non-genesis peers in the network.
#[cfg(debug_assertions)]
pub fn get_freeze_status_handles(&self) -> Vec<irohad::FreezeStatus> {
self.peers()
self.peers
.values()
.filter_map(|peer| peer.irohad.as_ref())
.map(|iroha| iroha.freeze_status())
.cloned()
Expand All @@ -329,12 +325,7 @@ impl Network {
/// Adds peer to network and waits for it to start block
/// synchronization.
pub async fn add_peer(&self) -> (Peer, Client) {
let client = Client::test(
&Network::peers(self)
.choose(&mut thread_rng())
.unwrap()
.api_address,
);
let client = Client::test(&self.first_peer.api_address);

let mut config = Config::test();
config.sumeragi.trusted_peers.value_mut().others =
Expand Down Expand Up @@ -378,7 +369,7 @@ impl Network {
/// # Panics
/// When unsuccessful after `MAX_RETRIES`.
pub fn wait_for_genesis_committed(clients: &[Client], offline_peers: u32) {
const MAX_RETRIES: u32 = 40;
const MAX_RETRIES: u32 = 200;
wait_for_genesis_committed_with_max_retries(clients, offline_peers, MAX_RETRIES)
}

Expand All @@ -392,7 +383,7 @@ pub fn wait_for_genesis_committed_with_max_retries(
offline_peers: u32,
max_retries: u32,
) {
const POLL_PERIOD: Duration = Duration::from_millis(1000);
const POLL_PERIOD: Duration = Duration::from_millis(5000);

for _ in 0..max_retries {
let ready_peers = clients
Expand Down

0 comments on commit be22388

Please sign in to comment.