Skip to content

Commit

Permalink
Fix for flaky base node tests (#1947)
Browse files Browse the repository at this point in the history
Merge pull request #1947

Fix for flaky base node tests

* pull/1947/head:
  Fix for flaky base node tests
  • Loading branch information
sdbondi committed Jun 4, 2020
2 parents fc1779e + 422f060 commit 139117a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 49 deletions.
35 changes: 16 additions & 19 deletions base_layer/core/tests/helpers/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use futures::Sink;
use rand::{distributions::Alphanumeric, rngs::OsRng, Rng};
use std::{error::Error, iter, sync::Arc, time::Duration};
use std::{error::Error, iter, path::Path, sync::Arc, time::Duration};
use tari_comms::{
peer_manager::{NodeIdentity, PeerFeatures},
transports::MemoryTransport,
Expand Down Expand Up @@ -275,28 +275,27 @@ pub fn create_network_with_2_base_nodes(
}

// Creates a network with two Base Nodes where each node in the network knows the other nodes in the network.
pub fn create_network_with_2_base_nodes_with_config(
pub fn create_network_with_2_base_nodes_with_config<P: AsRef<Path>>(
runtime: &mut Runtime,
base_node_service_config: BaseNodeServiceConfig,
mmr_cache_config: MmrCacheConfig,
mempool_service_config: MempoolServiceConfig,
liveness_service_config: LivenessConfig,
consensus_manager: ConsensusManager,
data_path: &str,
data_path: P,
) -> (NodeInterfaces, NodeInterfaces, ConsensusManager)
{
let alice_node_identity = random_node_identity();
let bob_node_identity = random_node_identity();
let network = Network::LocalNet;
let (alice_node, consensus_manager) = BaseNodeBuilder::new(network)
.with_node_identity(alice_node_identity.clone())
.with_peers(vec![bob_node_identity.clone()])
.with_base_node_service_config(base_node_service_config)
.with_mmr_cache_config(mmr_cache_config)
.with_mempool_service_config(mempool_service_config)
.with_liveness_service_config(liveness_service_config.clone())
.with_consensus_manager(consensus_manager)
.start(runtime, data_path);
.start(runtime, data_path.as_ref().join("alice").as_os_str().to_str().unwrap());
let (bob_node, consensus_manager) = BaseNodeBuilder::new(network)
.with_node_identity(bob_node_identity)
.with_peers(vec![alice_node_identity])
Expand All @@ -305,7 +304,7 @@ pub fn create_network_with_2_base_nodes_with_config(
.with_mempool_service_config(mempool_service_config)
.with_liveness_service_config(liveness_service_config.clone())
.with_consensus_manager(consensus_manager)
.start(runtime, data_path);
.start(runtime, data_path.as_ref().join("bob").as_os_str().to_str().unwrap());

wait_until_online(runtime, &[&alice_node, &bob_node]);

Expand Down Expand Up @@ -333,14 +332,14 @@ pub fn create_network_with_3_base_nodes(
}

// Creates a network with three Base Nodes where each node in the network knows the other nodes in the network.
pub fn create_network_with_3_base_nodes_with_config(
pub fn create_network_with_3_base_nodes_with_config<P: AsRef<Path>>(
runtime: &mut Runtime,
base_node_service_config: BaseNodeServiceConfig,
mmr_cache_config: MmrCacheConfig,
mempool_service_config: MempoolServiceConfig,
liveness_service_config: LivenessConfig,
consensus_manager: ConsensusManager,
data_path: &str,
data_path: P,
) -> (NodeInterfaces, NodeInterfaces, NodeInterfaces, ConsensusManager)
{
let alice_node_identity = random_node_identity();
Expand All @@ -354,34 +353,32 @@ pub fn create_network_with_3_base_nodes_with_config(
bob_node_identity.node_id().short_str(),
carol_node_identity.node_id().short_str()
);

let (alice_node, consensus_manager) = BaseNodeBuilder::new(network)
.with_node_identity(alice_node_identity.clone())
.with_peers(vec![bob_node_identity.clone(), carol_node_identity.clone()])
let (carol_node, consensus_manager) = BaseNodeBuilder::new(network)
.with_node_identity(carol_node_identity.clone())
.with_base_node_service_config(base_node_service_config)
.with_mmr_cache_config(mmr_cache_config)
.with_mempool_service_config(mempool_service_config)
.with_liveness_service_config(liveness_service_config.clone())
.with_consensus_manager(consensus_manager)
.start(runtime, data_path);
.start(runtime, data_path.as_ref().join("carol").as_os_str().to_str().unwrap());
let (bob_node, consensus_manager) = BaseNodeBuilder::new(network)
.with_node_identity(bob_node_identity.clone())
.with_peers(vec![carol_node_identity.clone(), alice_node_identity.clone()])
.with_peers(vec![carol_node_identity.clone()])
.with_base_node_service_config(base_node_service_config)
.with_mmr_cache_config(mmr_cache_config)
.with_mempool_service_config(mempool_service_config)
.with_liveness_service_config(liveness_service_config.clone())
.with_consensus_manager(consensus_manager)
.start(runtime, data_path);
let (carol_node, consensus_manager) = BaseNodeBuilder::new(network)
.with_node_identity(carol_node_identity.clone())
.with_peers(vec![alice_node_identity.clone(), bob_node_identity.clone()])
.start(runtime, data_path.as_ref().join("bob").as_os_str().to_str().unwrap());
let (alice_node, consensus_manager) = BaseNodeBuilder::new(network)
.with_node_identity(alice_node_identity.clone())
.with_peers(vec![bob_node_identity.clone(), carol_node_identity.clone()])
.with_base_node_service_config(base_node_service_config)
.with_mmr_cache_config(mmr_cache_config)
.with_mempool_service_config(mempool_service_config)
.with_liveness_service_config(liveness_service_config.clone())
.with_consensus_manager(consensus_manager)
.start(runtime, data_path);
.start(runtime, data_path.as_ref().join("alice").as_os_str().to_str().unwrap());

wait_until_online(runtime, &[&alice_node, &bob_node, &carol_node]);

Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/tests/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ fn request_response_get_stats() {
MempoolServiceConfig::default(),
LivenessConfig::default(),
consensus_manager,
temp_dir.path().to_str().unwrap(),
temp_dir.path(),
);

// Create a tx spending the genesis output. Then create 2 orphan txs
Expand Down
53 changes: 24 additions & 29 deletions base_layer/core/tests/node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,28 +408,23 @@ fn propagate_and_forward_valid_block() {
.build();
let (mut alice_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(alice_node_identity.clone())
.with_peers(vec![bob_node_identity.clone()])
.with_consensus_manager(rules)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
.start(&mut runtime, temp_dir.path().join("alice").to_str().unwrap());
let (bob_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(bob_node_identity.clone())
.with_peers(vec![
alice_node_identity,
carol_node_identity.clone(),
dan_node_identity.clone(),
])
.with_peers(vec![alice_node_identity])
.with_consensus_manager(rules)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
.start(&mut runtime, temp_dir.path().join("bob").to_str().unwrap());
let (carol_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(carol_node_identity.clone())
.with_peers(vec![bob_node_identity.clone(), dan_node_identity.clone()])
.with_peers(vec![bob_node_identity.clone()])
.with_consensus_manager(rules)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
.start(&mut runtime, temp_dir.path().join("carol").to_str().unwrap());
let (dan_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(dan_node_identity)
.with_peers(vec![bob_node_identity, carol_node_identity])
.with_peers(vec![carol_node_identity, bob_node_identity])
.with_consensus_manager(rules)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
.start(&mut runtime, temp_dir.path().join("dan").to_str().unwrap());

wait_until_online(&mut runtime, &[&alice_node, &bob_node, &carol_node, &dan_node]);

Expand Down Expand Up @@ -513,36 +508,36 @@ fn propagate_and_forward_invalid_block() {
let stateless_block_validator = StatelessBlockValidator::new(rules.clone(), factories.clone());
let mock_validator = MockValidator::new(true);
let mock_accum_difficulty_validator = MockAccumDifficultyValidator {};
let (mut alice_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(alice_node_identity.clone())
.with_peers(vec![bob_node_identity.clone(), carol_node_identity.clone()])

let (dan_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(dan_node_identity.clone())
.with_consensus_manager(rules)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
let (bob_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(bob_node_identity.clone())
.with_peers(vec![alice_node_identity.clone(), dan_node_identity.clone()])
.start(&mut runtime, temp_dir.path().join("dan").to_str().unwrap());
let (carol_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(carol_node_identity.clone())
.with_peers(vec![dan_node_identity.clone()])
.with_consensus_manager(rules)
.with_validators(
mock_validator.clone(),
stateless_block_validator.clone(),
mock_accum_difficulty_validator.clone(),
)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
let (carol_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(carol_node_identity.clone())
.with_peers(vec![alice_node_identity, dan_node_identity.clone()])
.start(&mut runtime, temp_dir.path().join("carol").to_str().unwrap());
let (bob_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(bob_node_identity.clone())
.with_peers(vec![dan_node_identity.clone()])
.with_consensus_manager(rules)
.with_validators(
mock_validator.clone(),
stateless_block_validator,
stateless_block_validator.clone(),
mock_accum_difficulty_validator.clone(),
)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
let (dan_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(dan_node_identity)
.with_peers(vec![bob_node_identity, carol_node_identity])
.start(&mut runtime, temp_dir.path().join("bob").to_str().unwrap());
let (mut alice_node, rules) = BaseNodeBuilder::new(network)
.with_node_identity(alice_node_identity)
.with_peers(vec![bob_node_identity.clone(), carol_node_identity.clone()])
.with_consensus_manager(rules)
.start(&mut runtime, temp_dir.path().to_str().unwrap());
.start(&mut runtime, temp_dir.path().join("alice").to_str().unwrap());

wait_until_online(&mut runtime, &[&alice_node, &bob_node, &carol_node, &dan_node]);

Expand Down

0 comments on commit 139117a

Please sign in to comment.