unittest for bind two consecutive ports (#23008)

* minor fix of comments in fork-selection tests

* fix doc link

* add unittest for bind_two_consecutive_in_range
This commit is contained in:
HaoranYi 2022-03-02 09:10:29 -06:00 committed by GitHub
parent 8de88d0a55
commit 4f0070a5c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -1,13 +1,13 @@
//! Fork Selection Simulation
//!
//! Description of the algorithm can be found in [docs/src/fork-selection.md](docs/src/fork-selection.md).
//! Description of the algorithm can be found in [docs/src/cluster/managing-forks.md](docs/src/cluster/managing-forks.md).
//!
//! A test library function exists for configuring networks.
//! ```
//! /// * num_partitions - 1 to 100 partitions
//! /// * fail_rate - 0 to 1.0 rate of packet receive failure
//! /// * delay_count - number of forks to observe before voting
//! /// * parasite_rate - number of parasite nodes that vote opposite the greedy choice
//! /// * parasite_rate - percentage of parasite nodes that vote opposite the greedy choice
//! fn test_with_partitions(num_partitions: usize, fail_rate: f64, delay_count: usize, parasite_rate: f64);
//! ```
//! Modify the test function
@ -497,7 +497,7 @@ fn test_no_partitions() {
/// * num_partitions - 1 to 100 partitions
/// * fail_rate - 0 to 1.0 rate of packet receive failure
/// * delay_count - number of forks to observe before voting
/// * parasite_rate - number of parasite nodes that vote opposite the greedy choice
/// * parasite_rate - percentage of parasite nodes that vote opposite the greedy choice
fn test_with_partitions(
num_partitions: usize,
fail_rate: f64,

View File

@ -790,4 +790,14 @@ mod tests {
3,
));
}
#[test]
fn test_bind_two_consecutive_in_range() {
solana_logger::setup();
let ip_addr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
if let Ok(((port1, _), (port2, _))) = bind_two_consecutive_in_range(ip_addr, (1024, 65535))
{
assert!(port2 == port1 + 1);
}
}
}