Skip to content

Commit

Permalink
Speedup and stabilize unit and integration tests
Browse files Browse the repository at this point in the history
- Removed usage of `mdns = true` from all test except one(which tests it)
- `P2PService::start`is async function now and awaits getting of any address
  • Loading branch information
xgreenx committed Jun 28, 2023
1 parent caf5397 commit 51219f5
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 371 deletions.
27 changes: 9 additions & 18 deletions crates/fuel-core/src/p2p_test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{
use fuel_core_p2p::{
codecs::postcard::PostcardCodec,
network_service::FuelP2PService,
PeerId,
};
use fuel_core_poa::{
ports::BlockImporter,
Expand Down Expand Up @@ -110,27 +109,15 @@ pub struct Nodes {
/// Nodes accessible by their name.
pub struct NamedNodes(pub HashMap<String, Node>);

fn map_listener_address(bootstrap_id: &PeerId, addr: &Multiaddr) -> Multiaddr {
format!("{addr}/p2p/{bootstrap_id}").parse().unwrap()
}

impl Bootstrap {
/// Spawn a bootstrap node.
pub async fn new(node_config: &Config) -> Self {
let bootstrap_config = extract_p2p_config(node_config);
let codec = PostcardCodec::new(bootstrap_config.max_block_size);
let mut bootstrap = FuelP2PService::new(bootstrap_config, codec);
bootstrap.start().unwrap();
bootstrap.start().await.unwrap();

// Wait for listener addresses.
while bootstrap.listeners().next().is_none() {
bootstrap.next_event().await;
}

let listeners: Vec<_> = bootstrap
.listeners()
.map(|addr| map_listener_address(&bootstrap.local_peer_id, addr))
.collect();
let listeners = bootstrap.multiaddrs();
let (kill, mut shutdown) = broadcast::channel(1);
tokio::spawn(async move {
loop {
Expand Down Expand Up @@ -325,9 +312,13 @@ pub fn make_config(name: String, chain_config: ChainConfig) -> Config {

pub async fn make_node(node_config: Config, test_txs: Vec<Transaction>) -> Node {
let db = Database::in_memory();
let node = FuelService::from_database(db.clone(), node_config)
.await
.unwrap();
let node = tokio::time::timeout(
Duration::from_secs(1),
FuelService::from_database(db.clone(), node_config),
)
.await
.expect("All services should start in less than 1 second")
.expect("The `FuelService should start without error");

let config = node.shared.config.clone();
Node {
Expand Down
Loading

0 comments on commit 51219f5

Please sign in to comment.