mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 09:07:57 +00:00
substrate runner: increase line read + dump CLI output if parsing fails (#1781)
* substrate runner: dump CLI output parsing fails * cargo fmt * Update testing/substrate-runner/src/lib.rs * fix grumbles * disable flaky test * ignore reconn test too * ignore more tests * fix tests * improve log parsing * Update testing/integration-tests/src/full_client/client/unstable_rpcs.rs * Update testing/integration-tests/src/full_client/client/unstable_rpcs.rs * fix nits * fix reconn test
This commit is contained in:
@@ -5,26 +5,26 @@
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Io(std::io::Error),
|
||||
CouldNotExtractPort,
|
||||
CouldNotExtractP2pAddress,
|
||||
CouldNotExtractP2pPort,
|
||||
CouldNotExtractPort(String),
|
||||
CouldNotExtractP2pAddress(String),
|
||||
CouldNotExtractP2pPort(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::Io(err) => write!(f, "IO error: {err}"),
|
||||
Error::CouldNotExtractPort => write!(
|
||||
Error::CouldNotExtractPort(log) => write!(
|
||||
f,
|
||||
"could not extract port from running substrate node's stdout"
|
||||
"could not extract port from running substrate node's stdout: {log}"
|
||||
),
|
||||
Error::CouldNotExtractP2pAddress => write!(
|
||||
Error::CouldNotExtractP2pAddress(log) => write!(
|
||||
f,
|
||||
"could not extract p2p address from running substrate node's stdout"
|
||||
"could not extract p2p address from running substrate node's stdout: {log}"
|
||||
),
|
||||
Error::CouldNotExtractP2pPort => write!(
|
||||
Error::CouldNotExtractP2pPort(log) => write!(
|
||||
f,
|
||||
"could not extract p2p port from running substrate node's stdout"
|
||||
"could not extract p2p port from running substrate node's stdout: {log}"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +102,11 @@ impl SubstrateNodeBuilder {
|
||||
|
||||
// Wait for RPC port to be logged (it's logged to stderr).
|
||||
let stderr = proc.stderr.take().unwrap();
|
||||
let (ws_port, p2p_address, p2p_port) = try_find_substrate_port_from_output(stderr);
|
||||
let running_node = try_find_substrate_port_from_output(stderr);
|
||||
|
||||
let ws_port = ws_port.ok_or(Error::CouldNotExtractPort)?;
|
||||
let p2p_address = p2p_address.ok_or(Error::CouldNotExtractP2pAddress)?;
|
||||
let p2p_port = p2p_port.ok_or(Error::CouldNotExtractP2pPort)?;
|
||||
let ws_port = running_node.ws_port()?;
|
||||
let p2p_address = running_node.p2p_address()?;
|
||||
let p2p_port = running_node.p2p_port()?;
|
||||
|
||||
Ok(SubstrateNode {
|
||||
binary_path: bin_path,
|
||||
@@ -244,16 +244,19 @@ impl Drop for SubstrateNode {
|
||||
|
||||
// Consume a stderr reader from a spawned substrate command and
|
||||
// locate the port number that is logged out to it.
|
||||
fn try_find_substrate_port_from_output(
|
||||
r: impl Read + Send + 'static,
|
||||
) -> (Option<u16>, Option<String>, Option<u32>) {
|
||||
fn try_find_substrate_port_from_output(r: impl Read + Send + 'static) -> SubstrateNodeInfo {
|
||||
let mut port = None;
|
||||
let mut p2p_address = None;
|
||||
let mut p2p_port = None;
|
||||
|
||||
for line in BufReader::new(r).lines().take(50) {
|
||||
let mut log = String::new();
|
||||
|
||||
for line in BufReader::new(r).lines().take(100) {
|
||||
let line = line.expect("failed to obtain next line from stdout for port discovery");
|
||||
|
||||
log.push_str(&line);
|
||||
log.push('\n');
|
||||
|
||||
// Parse the port lines
|
||||
let line_port = line
|
||||
// oldest message:
|
||||
@@ -301,7 +304,43 @@ fn try_find_substrate_port_from_output(
|
||||
.unwrap_or_else(|_| panic!("valid port expected for log line, got '{port_str}'"));
|
||||
p2p_port = Some(port_num);
|
||||
}
|
||||
|
||||
if port.is_some() && p2p_address.is_some() && p2p_port.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(port, p2p_address, p2p_port)
|
||||
SubstrateNodeInfo {
|
||||
ws_port: port,
|
||||
p2p_address,
|
||||
p2p_port,
|
||||
log,
|
||||
}
|
||||
}
|
||||
|
||||
/// Data extracted from the running node's stdout.
|
||||
#[derive(Debug)]
|
||||
pub struct SubstrateNodeInfo {
|
||||
ws_port: Option<u16>,
|
||||
p2p_address: Option<String>,
|
||||
p2p_port: Option<u32>,
|
||||
log: String,
|
||||
}
|
||||
|
||||
impl SubstrateNodeInfo {
|
||||
pub fn ws_port(&self) -> Result<u16, Error> {
|
||||
self.ws_port
|
||||
.ok_or_else(|| Error::CouldNotExtractPort(self.log.clone()))
|
||||
}
|
||||
|
||||
pub fn p2p_address(&self) -> Result<String, Error> {
|
||||
self.p2p_address
|
||||
.clone()
|
||||
.ok_or_else(|| Error::CouldNotExtractP2pAddress(self.log.clone()))
|
||||
}
|
||||
|
||||
pub fn p2p_port(&self) -> Result<u32, Error> {
|
||||
self.p2p_port
|
||||
.ok_or_else(|| Error::CouldNotExtractP2pPort(self.log.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user