fix tests

This commit is contained in:
John Smith 2022-05-01 11:01:29 -04:00
parent 95aa8352d4
commit a20b42aae1
4 changed files with 29 additions and 4 deletions

View File

@ -52,7 +52,7 @@ def tee(prefix, infile, *files):
def read_until_interface_dial_info(proc, proto): def read_until_interface_dial_info(proc, proto):
interface_dial_info_str = b"Interface Dial Info: " interface_dial_info_str = b"Local Dial Info: "
for ln in iter(proc.stdout.readline, ""): for ln in iter(proc.stdout.readline, ""):
sys.stdout.buffer.write(ln) sys.stdout.buffer.write(ln)
sys.stdout.flush() sys.stdout.flush()

View File

@ -1257,7 +1257,8 @@ impl NetworkManager {
let inner = self.inner.lock(); let inner = self.inner.lock();
let mut inconsistencies = 0; let mut inconsistencies = 0;
let mut changed = false; let mut changed = false;
for (p, a) in &inner.public_address_check_cache { // Iteration goes from most recent to least recent node/address pair
for (_, a) in &inner.public_address_check_cache {
if !current_addresses.contains(a) { if !current_addresses.contains(a) {
inconsistencies += 1; inconsistencies += 1;
if inconsistencies >= GLOBAL_ADDRESS_CHANGE_DETECTION_COUNT { if inconsistencies >= GLOBAL_ADDRESS_CHANGE_DETECTION_COUNT {
@ -1276,7 +1277,8 @@ impl NetworkManager {
let mut consistencies = 0; let mut consistencies = 0;
let mut consistent = false; let mut consistent = false;
let mut current_address = Option::<SocketAddress>::None; let mut current_address = Option::<SocketAddress>::None;
for (p, a) in &inner.public_address_check_cache { // Iteration goes from most recent to least recent node/address pair
for (_, a) in &inner.public_address_check_cache {
if let Some(current_address) = current_address { if let Some(current_address) = current_address {
if current_address == *a { if current_address == *a {
consistencies += 1; consistencies += 1;

View File

@ -386,6 +386,13 @@ pub async fn test_split_url() {
assert_split_url!("http://foo/", "http", host("foo"), None, ""); assert_split_url!("http://foo/", "http", host("foo"), None, "");
assert_split_url!("http://11.2.3.144/", "http", ip("11.2.3.144"), None, ""); assert_split_url!("http://11.2.3.144/", "http", ip("11.2.3.144"), None, "");
assert_split_url!("http://[1111::2222]/", "http", ip("1111::2222"), None, ""); assert_split_url!("http://[1111::2222]/", "http", ip("1111::2222"), None, "");
assert_split_url!(
"http://[1111::2222]:123/",
"http",
ip("1111::2222"),
Some(123),
""
);
assert_split_url!( assert_split_url!(
"http://foo/asdf/qwer", "http://foo/asdf/qwer",
@ -433,6 +440,8 @@ pub async fn test_split_url() {
assert_err!(SplitUrl::from_str("a:///qwer:")); assert_err!(SplitUrl::from_str("a:///qwer:"));
assert_err!(SplitUrl::from_str("a:///qwer://")); assert_err!(SplitUrl::from_str("a:///qwer://"));
assert_err!(SplitUrl::from_str("a://qwer://")); assert_err!(SplitUrl::from_str("a://qwer://"));
assert_err!(SplitUrl::from_str("a://[1111::2222]:/"));
assert_err!(SplitUrl::from_str("a://[1111::2222]:"));
assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord#qux?zuz"); assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord#qux?zuz");
assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord#qux"); assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord#qux");

View File

@ -296,6 +296,20 @@ impl SplitUrl {
} }
} }
fn split_host_with_port(s: &str) -> Option<(&str, &str)> {
// special case for ipv6 colons
if s.len() > 2 && s[0..1] == *"[" {
if let Some(end) = s.find(']') {
if end < (s.len() - 2) && s[end + 1..end + 2] == *":" {
return Some((&s[0..end + 1], &s[end + 2..]));
}
}
None
} else {
s.split_once(':')
}
}
impl FromStr for SplitUrl { impl FromStr for SplitUrl {
type Err = String; type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -311,7 +325,7 @@ impl FromStr for SplitUrl {
None None
} }
}; };
if let Some((host, rest)) = rest.rsplit_once(':') { if let Some((host, rest)) = split_host_with_port(rest) {
let host = SplitUrlHost::from_str(host)?; let host = SplitUrlHost::from_str(host)?;
if let Some((portstr, path)) = rest.split_once('/') { if let Some((portstr, path)) = rest.split_once('/') {
let port = convert_port(portstr)?; let port = convert_port(portstr)?;