From f3c9b830569fb63f917586b774571858e0121f5a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 12 May 2022 14:07:30 +0300 Subject: [PATCH 1/2] Find substrate port on different log lines Signed-off-by: Alexandru Vasile --- integration-tests/src/utils/node_proc.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/integration-tests/src/utils/node_proc.rs b/integration-tests/src/utils/node_proc.rs index 16e5d8887f..f692f15e03 100644 --- a/integration-tests/src/utils/node_proc.rs +++ b/integration-tests/src/utils/node_proc.rs @@ -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:") + { + 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) }) From b61e489d31c88f773dbc3b3b98c925dd2ed9b574 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 12 May 2022 15:41:17 +0300 Subject: [PATCH 2/2] Simplify node_proc line logic Signed-off-by: Alexandru Vasile --- integration-tests/src/utils/node_proc.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/integration-tests/src/utils/node_proc.rs b/integration-tests/src/utils/node_proc.rs index f692f15e03..280dc91076 100644 --- a/integration-tests/src/utils/node_proc.rs +++ b/integration-tests/src/utils/node_proc.rs @@ -172,18 +172,12 @@ fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> u16 { 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 + let line_end = 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:") - { - None => return None, - Some((_, after)) => after, - } - } - Some((_, after)) => after, - }; + .or_else(|| { + line.rsplit_once("Running JSON-RPC WS server: addr=127.0.0.1:") + }) + .map(|(_, port_str)| port_str)?; // 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));