forked from AleoNet/snarkOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ljedrz <[email protected]>
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (C) 2019-2022 Aleo Systems Inc. | ||
// This file is part of the snarkOS library. | ||
|
||
// The snarkOS library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// The snarkOS library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use std::time::{Duration, Instant}; | ||
|
||
use pea2pea::Pea2Pea; | ||
use snarkos_crawler::crawler::{Crawler, Opts}; | ||
use snarkos_integration::TestNode; | ||
|
||
const NUM_NODES: usize = 10; | ||
|
||
#[tokio::test] | ||
async fn basics() { | ||
// tracing_subscriber::fmt::init(); | ||
|
||
// Prepare some collections we'll be using. | ||
let mut test_nodes = Vec::with_capacity(NUM_NODES); | ||
let mut test_node_addrs = Vec::with_capacity(NUM_NODES); | ||
|
||
// Start the test nodes. | ||
for _ in 0..NUM_NODES { | ||
let test_node = TestNode::default().await; | ||
let test_node_addr = test_node.node().listening_addr().unwrap(); | ||
|
||
test_nodes.push(test_node); | ||
test_node_addrs.push(test_node_addr); | ||
} | ||
|
||
// Connect the test nodes into a linear topology. | ||
for (node, prev_node_addr) in test_nodes.iter().skip(1).zip(&test_node_addrs) { | ||
node.node().connect(*prev_node_addr).await.unwrap(); | ||
} | ||
|
||
// Double-check the topology. | ||
for (i, node) in test_nodes.iter().enumerate() { | ||
if i == 0 || i == NUM_NODES - 1 { | ||
assert_eq!(node.node().num_connected(), 1); | ||
} else { | ||
assert_eq!(node.node().num_connected(), 2); | ||
} | ||
} | ||
|
||
// Start the crawler. | ||
let opts = Opts { | ||
node: "127.0.0.1:0".parse().unwrap(), | ||
}; | ||
let crawler = Crawler::new(opts).await; | ||
|
||
// "Seed" the crawler with the address of the first node. | ||
crawler.known_network.add_node(test_node_addrs[0]); | ||
|
||
// Initialize the crawler. | ||
crawler.run_periodic_tasks(); | ||
|
||
let now = Instant::now(); | ||
loop { | ||
if crawler.node().num_connected() == NUM_NODES { | ||
break; | ||
} | ||
tokio::time::sleep(Duration::from_millis(1)).await; | ||
assert!(now.elapsed() <= Duration::from_secs(5), "timed out!"); | ||
} | ||
} |