This commit is contained in:
parent
abaff96f7d
commit
e0c63415d3
1 changed files with 23 additions and 15 deletions
34
src/test.rs
34
src/test.rs
|
@ -1,6 +1,6 @@
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::{Arc};
|
use std::sync::Arc;
|
||||||
use std::time::{Duration};
|
use std::time::Duration;
|
||||||
|
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
@ -8,11 +8,10 @@ use tokio::sync::watch;
|
||||||
use sodiumoxide::crypto::auth;
|
use sodiumoxide::crypto::auth;
|
||||||
use sodiumoxide::crypto::sign::ed25519;
|
use sodiumoxide::crypto::sign::ed25519;
|
||||||
|
|
||||||
use crate::peering::fullmesh::*;
|
|
||||||
use crate::netapp::*;
|
use crate::netapp::*;
|
||||||
|
use crate::peering::fullmesh::*;
|
||||||
use crate::NodeID;
|
use crate::NodeID;
|
||||||
|
|
||||||
|
|
||||||
#[tokio::test(flavor = "current_thread")]
|
#[tokio::test(flavor = "current_thread")]
|
||||||
async fn test_with_basic_scheduler() {
|
async fn test_with_basic_scheduler() {
|
||||||
run_test().await
|
run_test().await
|
||||||
|
@ -43,11 +42,19 @@ async fn run_test_inner() {
|
||||||
|
|
||||||
let (stop_tx, stop_rx) = watch::channel(false);
|
let (stop_tx, stop_rx) = watch::channel(false);
|
||||||
|
|
||||||
let (thread1, _netapp1, peering1) = run_netapp(netid.clone(), pk1, sk1, addr1, vec![], stop_rx.clone());
|
let (thread1, _netapp1, peering1) =
|
||||||
|
run_netapp(netid.clone(), pk1, sk1, addr1, vec![], stop_rx.clone());
|
||||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
|
|
||||||
// Connect second node and check it peers with everyone
|
// Connect second node and check it peers with everyone
|
||||||
let (thread2, _netapp2, peering2) = run_netapp(netid.clone(), pk2, sk2, addr2, vec![(pk1, addr1)], stop_rx.clone());
|
let (thread2, _netapp2, peering2) = run_netapp(
|
||||||
|
netid.clone(),
|
||||||
|
pk2,
|
||||||
|
sk2,
|
||||||
|
addr2,
|
||||||
|
vec![(pk1, addr1)],
|
||||||
|
stop_rx.clone(),
|
||||||
|
);
|
||||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||||
|
|
||||||
let pl1 = peering1.get_peer_list();
|
let pl1 = peering1.get_peer_list();
|
||||||
|
@ -59,7 +66,8 @@ async fn run_test_inner() {
|
||||||
assert_eq!(pl2.len(), 2);
|
assert_eq!(pl2.len(), 2);
|
||||||
|
|
||||||
// Connect third ndoe and check it peers with everyone
|
// Connect third ndoe and check it peers with everyone
|
||||||
let (thread3, _netapp3, peering3) = run_netapp(netid, pk3, sk3, addr3, vec![(pk2, addr2)], stop_rx.clone());
|
let (thread3, _netapp3, peering3) =
|
||||||
|
run_netapp(netid, pk3, sk3, addr3, vec![(pk2, addr2)], stop_rx.clone());
|
||||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||||
|
|
||||||
let pl1 = peering1.get_peer_list();
|
let pl1 = peering1.get_peer_list();
|
||||||
|
@ -87,11 +95,12 @@ fn run_netapp(
|
||||||
sk: ed25519::SecretKey,
|
sk: ed25519::SecretKey,
|
||||||
listen_addr: SocketAddr,
|
listen_addr: SocketAddr,
|
||||||
bootstrap_peers: Vec<(NodeID, SocketAddr)>,
|
bootstrap_peers: Vec<(NodeID, SocketAddr)>,
|
||||||
must_exit: watch::Receiver<bool>)
|
must_exit: watch::Receiver<bool>,
|
||||||
->
|
) -> (
|
||||||
(tokio::task::JoinHandle<()>, Arc<NetApp>, Arc<FullMeshPeeringStrategy>)
|
tokio::task::JoinHandle<()>,
|
||||||
{
|
Arc<NetApp>,
|
||||||
|
Arc<FullMeshPeeringStrategy>,
|
||||||
|
) {
|
||||||
let netapp = NetApp::new(netid, sk);
|
let netapp = NetApp::new(netid, sk);
|
||||||
let peering = FullMeshPeeringStrategy::new(netapp.clone(), bootstrap_peers);
|
let peering = FullMeshPeeringStrategy::new(netapp.clone(), bootstrap_peers);
|
||||||
|
|
||||||
|
@ -106,4 +115,3 @@ fn run_netapp(
|
||||||
|
|
||||||
(fut, netapp, peering)
|
(fut, netapp, peering)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue