Skip to content

Commit

Permalink
show logging on failed cli tests & adjust candidate_endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ramfox committed Jun 27, 2023
1 parent 2c41eed commit 0cecc4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 3 additions & 10 deletions iroh-net/src/hp/magicsock/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Endpoint {
}
}
None => {
let (addr, should_ping) = self.get_candidate_udp_addr(now);
let (addr, should_ping) = self.get_candidate_udp_addr();

// provide backup derp addr if no known latency or no addr
let derp_addr = if should_ping || addr.is_none() {
Expand All @@ -152,13 +152,14 @@ impl Endpoint {
None
};

debug!("using candidate addr {addr:?}, derp addr: {derp_addr:?}");
(addr, derp_addr, should_ping)
}
}
}

/// Determines a potential best addr for this endpoint. And if the endpoint needs a ping.
fn get_candidate_udp_addr(&mut self, now: &Instant) -> (Option<SocketAddr>, bool) {
fn get_candidate_udp_addr(&mut self) -> (Option<SocketAddr>, bool) {
let mut lowest_latency = Duration::from_secs(60 * 60);
let mut last_pong = None;
for (ipp, state) in self.endpoint_state.iter() {
Expand Down Expand Up @@ -192,14 +193,6 @@ impl Endpoint {
.keys()
.choose_stable(&mut rand::thread_rng())
.copied();
if let Some(addr) = udp_addr {
self.best_addr = Some(AddrLatency {
addr,
latency: None,
});

self.trust_best_addr_until = Some(*now + Duration::from_secs(15));
}

(udp_addr, udp_addr.is_some())
}
Expand Down
12 changes: 7 additions & 5 deletions iroh/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn make_partial_download(out_dir: &Path) -> anyhow::Result<Hash> {
}

#[test]
fn cli_provide_one_file() -> Result<()> {
fn cli_provide_one_file_basic() -> Result<()> {
let dir = testdir!();
let path = dir.join("foo");
make_rand_file(1000, &path)?;
Expand Down Expand Up @@ -376,8 +376,12 @@ fn test_provide_get_loop(path: &Path, input: Input, output: Output) -> Result<()
.stderr_capture();

// test get stderr output
let get_output = cmd.run()?;
let get_output = cmd.unchecked().run()?;
drop(provider);

// checking the output first, so you can still view any logging
assert!(!get_output.stderr.is_empty());
match_get_stderr(get_output.stderr)?;
assert!(get_output.status.success());

// test output
Expand All @@ -389,9 +393,7 @@ fn test_provide_get_loop(path: &Path, input: Input, output: Output) -> Result<()
}
Some(out) => compare_files(path, out)?,
};

assert!(!get_output.stderr.is_empty());
match_get_stderr(get_output.stderr)
Ok(())
}

/// Test the provide and get loop for success, stderr output, and file contents.
Expand Down

0 comments on commit 0cecc4b

Please sign in to comment.