Skip to content

Commit

Permalink
tests: fix tests for best_addr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Oct 19, 2023
1 parent 7e5e6ce commit 14e2665
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
32 changes: 14 additions & 18 deletions iroh-net/src/magicsock/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,12 +1625,12 @@ mod tests {
public_key: key.public(),
last_full_ping: None,
derp_region: new_relay_and_state(Some(0)),
best_addr: Some(AddrLatency {
addr: ip_port.into(),
latency: Some(latency),
}),
best_addr_at: Some(now),
trust_best_addr_until: now.checked_add(Duration::from_secs(100)),
best_addr: BestAddr::from_parts(
ip_port.into(),
Some(latency),
now,
now + Duration::from_secs(100),
),
direct_addr_state: endpoint_state,
is_call_me_maybe_ep: HashMap::new(),
pending_cli_pings: Vec::new(),
Expand Down Expand Up @@ -1660,9 +1660,7 @@ mod tests {
public_key: key.public(),
last_full_ping: None,
derp_region: Some((0, relay_state)),
best_addr: None,
best_addr_at: None,
trust_best_addr_until: now.checked_sub(Duration::from_secs(100)),
best_addr: BestAddr::default(),
direct_addr_state: HashMap::default(),
is_call_me_maybe_ep: HashMap::new(),
pending_cli_pings: Vec::new(),
Expand All @@ -1683,9 +1681,7 @@ mod tests {
public_key: key.public(),
last_full_ping: None,
derp_region: new_relay_and_state(Some(0)),
best_addr: None,
best_addr_at: None,
trust_best_addr_until: now.checked_sub(Duration::from_secs(100)),
best_addr: BestAddr::default(),
direct_addr_state: endpoint_state,
is_call_me_maybe_ep: HashMap::new(),
pending_cli_pings: Vec::new(),
Expand Down Expand Up @@ -1728,12 +1724,12 @@ mod tests {
public_key: key.public(),
last_full_ping: None,
derp_region: Some((0, relay_state)),
best_addr: Some(AddrLatency {
addr: socket_addr,
latency: Some(Duration::from_millis(80)),
}),
best_addr_at: Some(now),
trust_best_addr_until: Some(expired),
best_addr: BestAddr::from_parts(
socket_addr,
Some(Duration::from_millis(80)),
now,
expired,
),
direct_addr_state: endpoint_state,
is_call_me_maybe_ep: HashMap::new(),
pending_cli_pings: Vec::new(),
Expand Down
14 changes: 14 additions & 0 deletions iroh-net/src/magicsock/endpoint/best_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ pub enum BestAddrClearReason {
}

impl BestAddr {
#[cfg(test)]
pub fn from_parts(
addr: SocketAddr,
latency: Option<Duration>,
confirmed_at: Instant,
trust_until: Instant,
) -> Self {
let inner = BestAddrInner {
addr: AddrLatency { addr, latency },
confirmed_at,
trust_until: Some(trust_until),
};
Self(Some(inner))
}
pub fn is_empty(&self) -> bool {
self.0.is_none()
}
Expand Down

0 comments on commit 14e2665

Please sign in to comment.