From f263d85aa48915a58b72e74fb875cf86f21f79c6 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Mon, 24 May 2021 20:37:28 +0000 Subject: [PATCH] Test `last_seen` time being equal to the limit If the most recent `last_seen` time reported by a peer is exactly the limit, the offset doesn't need to be applied because no times are in the future. --- .../peer_set/candidate_set/tests/vectors.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/zebra-network/src/peer_set/candidate_set/tests/vectors.rs b/zebra-network/src/peer_set/candidate_set/tests/vectors.rs index bf13da31..19e4855b 100644 --- a/zebra-network/src/peer_set/candidate_set/tests/vectors.rs +++ b/zebra-network/src/peer_set/candidate_set/tests/vectors.rs @@ -80,6 +80,25 @@ fn offsets_all_last_seen_times_if_one_is_in_the_future() { assert_eq!(validated_peers, expected_peers); } +/// Test that offset is not applied if the most recent `last_seen` time is equal to the limit. +#[test] +fn doesnt_offsets_if_most_recent_last_seen_times_is_exactly_the_limit() { + let last_seen_limit = DateTime32::now(); + let last_seen_limit_chrono = last_seen_limit.to_chrono(); + + let input_peers = mock_gossiped_peers(vec![ + last_seen_limit_chrono, + last_seen_limit_chrono - Duration::minutes(3), + last_seen_limit_chrono - Duration::hours(1), + ]); + + let validated_peers: Vec<_> = validate_addrs(input_peers.clone(), last_seen_limit).collect(); + + let expected_peers = input_peers; + + assert_eq!(validated_peers, expected_peers); +} + /// Create a mock list of gossiped [`MetaAddr`]s with the specified `last_seen_times`. /// /// The IP address and port of the generated ports should not matter for the test.