-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Find substrate port on different log lines #536
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,22 +168,30 @@ fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> u16 { | |
BufReader::new(r) | ||
.lines() | ||
.find_map(|line| { | ||
let line = line | ||
.expect("failed to obtain next line from stdout for port discovery"); | ||
let line = | ||
line.expect("failed to obtain next line from stdout for port discovery"); | ||
|
||
// does the line contain our port (we expect this specific output from substrate). | ||
let line_end = match line.rsplit_once("Listening for new connections on 127.0.0.1:") { | ||
None => return None, | ||
Some((_, after)) => after | ||
let line_end = match line | ||
.rsplit_once("Listening for new connections on 127.0.0.1:") | ||
{ | ||
None => { | ||
match line.rsplit_once("Running JSON-RPC WS server: addr=127.0.0.1:") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could also do: https://github.com/paritytech/substrate/blob/master/bin/node/cli/tests/common.rs#L164-#L167 then just parse it as would be better than to assume that the address is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I didn't think about making the log easy to parse :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the testing pov I guess it's ok assuming 127.0.0.1 though (ie you could start it on 0.0.0.0, but you couldn't then connect to 0.0.0.0)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's fair assumption, I was thinking that some weird platforms could actually have some other loopback address than 127.0.0.1. Picking hair here just ignore me but I was more thinking about having to avoid parsing the port manually :P I think you can connect to 0.0.0.0 but it means all addresses IIRC. |
||
{ | ||
None => return None, | ||
Some((_, after)) => after, | ||
} | ||
} | ||
Some((_, after)) => after, | ||
}; | ||
|
||
// trim non-numeric chars from the end of the port part of the line. | ||
let port_str = line_end.trim_end_matches(|b| !('0'..='9').contains(&b)); | ||
|
||
// expect to have a number here (the chars after '127.0.0.1:') and parse them into a u16. | ||
let port_num = port_str | ||
.parse() | ||
.unwrap_or_else(|_| panic!("valid port expected on 'Listening for new connections' line, got '{port_str}'")); | ||
let port_num = port_str.parse().unwrap_or_else(|_| { | ||
panic!("valid port expected for log line, got '{port_str}'") | ||
}); | ||
|
||
Some(port_num) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could simplify this matching code to be: