Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VanBarbascu committed Apr 4, 2023
1 parent a13b486 commit 9e39cf6
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions chain/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ impl std::ops::Deref for VerifiedConfig {
mod test {
use super::UPDATE_INTERVAL_LAST_TIME_RECEIVED_MESSAGE;
use crate::config;
use crate::config_json::NetworkConfigOverrides;
use crate::network_protocol;
use crate::network_protocol::testonly as data;
use crate::network_protocol::{AccountData, VersionedAccountData};
Expand Down Expand Up @@ -509,6 +510,92 @@ mod test {
assert!(nc.verify().is_err());
}

#[test]
fn test_network_config_override() {
fn check_override_field<T: std::cmp::PartialEq>(
before: &T,
after: &T,
override_val: &Option<T>,
) -> bool {
if let Some(val) = override_val {
return after == val;
} else {
return after == before;
}
}
let check_fields = |before: &config::NetworkConfig,
after: &config::NetworkConfig,
overrides: &NetworkConfigOverrides| {
assert!(check_override_field(
&before.connect_to_reliable_peers_on_startup,
&after.connect_to_reliable_peers_on_startup,
&overrides.connect_to_reliable_peers_on_startup
));
assert!(check_override_field(
&before.max_send_peers,
&after.max_send_peers,
&overrides.max_send_peers
));
assert!(check_override_field(
&before.routed_message_ttl,
&after.routed_message_ttl,
&overrides.routed_message_ttl
));
assert!(check_override_field(
&before.max_routes_to_store,
&after.max_routes_to_store,
&overrides.max_routes_to_store
));
assert!(check_override_field(
&before.highest_peer_horizon,
&after.highest_peer_horizon,
&overrides.highest_peer_horizon
));
assert!(check_override_field(
&before.push_info_period,
&after.push_info_period,
&overrides
.push_info_period_millis
.map(|millis| time::Duration::milliseconds(millis))
));
assert!(check_override_field(
&before.outbound_disabled,
&after.outbound_disabled,
&overrides.outbound_disabled
));
assert!(check_override_field(
&before.accounts_data_broadcast_rate_limit.burst,
&after.accounts_data_broadcast_rate_limit.burst,
&overrides.accounts_data_broadcast_rate_limit_burst
));
assert!(check_override_field(
&before.accounts_data_broadcast_rate_limit.qps,
&after.accounts_data_broadcast_rate_limit.qps,
&overrides.accounts_data_broadcast_rate_limit_qps
));
};
let no_overrides = NetworkConfigOverrides::default();
let mut overrides = NetworkConfigOverrides::default();
overrides.connect_to_reliable_peers_on_startup = Some(false);
overrides.max_send_peers = Some(42);
overrides.routed_message_ttl = Some(43);
overrides.accounts_data_broadcast_rate_limit_burst = Some(44);
overrides.accounts_data_broadcast_rate_limit_qps = Some(45.0);

let nc_before =
config::NetworkConfig::from_seed("123", tcp::ListenerAddr::reserve_for_test());

let mut nc_after = nc_before.clone();
nc_after.override_config(no_overrides.clone());
check_fields(&nc_before, &nc_after, &no_overrides);
assert!(nc_after.verify().is_ok());

nc_after = nc_before.clone();
nc_after.override_config(overrides.clone());
check_fields(&nc_before, &nc_after, &overrides);
assert!(nc_after.verify().is_ok());
}

// Check that MAX_PEER_ADDRS limit is consistent with the
// network_protocol::MAX_ACCOUNT_DATA_SIZE_BYTES limit
#[test]
Expand Down

0 comments on commit 9e39cf6

Please sign in to comment.