use std::time::Duration;
use crate::Config;
use super::super::*;
use futures::stream::FuturesUnordered;
use tokio_stream::StreamExt;
use Network::*;
const MAX_TEST_DURATION: Duration = Duration::from_secs(20);
#[tokio::test]
async fn connect_isolated_run_tor_once() {
let _init_guard = zebra_test::init();
if zebra_test::net::zebra_skip_network_tests() {
return;
}
let config = Config::default();
let seeder_hostname = config
.initial_peer_hostnames()
.iter()
.next()
.unwrap()
.clone();
connect_isolated_run_tor_once_with(Mainnet, seeder_hostname).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn connect_isolated_run_tor_multi() {
let _init_guard = zebra_test::init();
if zebra_test::net::zebra_skip_network_tests() {
return;
}
let mut isolated_conns = FuturesUnordered::new();
for network in [Mainnet, Testnet] {
let config = Config {
network,
..Config::default()
};
for seeder_hostname in config.initial_peer_hostnames().iter().cloned() {
let conn = connect_isolated_run_tor_once_with(network, seeder_hostname);
isolated_conns.push(conn);
}
}
while let Some(()) = isolated_conns.next().await {}
}
async fn connect_isolated_run_tor_once_with(network: Network, hostname: String) {
let mut outbound_join_handle =
tokio::spawn(connect_isolated_tor(network, hostname, "".to_string()));
let outbound_join_handle_timeout =
tokio::time::timeout(MAX_TEST_DURATION, &mut outbound_join_handle);
let outbound_result = outbound_join_handle_timeout.await;
assert!(matches!(outbound_result, Ok(Ok(_)) | Err(_)));
outbound_join_handle.abort();
}