Skip to content
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

substrate runner: increase line read + dump CLI output if parsing fails #1781

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ thiserror = "1.0.63"
tokio = { version = "1.40", default-features = false }
tracing = { version = "0.1.40", default-features = false }
tracing-wasm = "0.2.1"
tracing-subscriber = "0.3.18"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
trybuild = "1.0.99"
url = "2.5.2"
wabt = "0.10.0"
Expand Down
2 changes: 2 additions & 0 deletions testing/integration-tests/src/full_client/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ async fn block_subscriptions_are_consistent_with_eachother() -> Result<(), subxt
Ok(())
}

// TODO: flaky test https://github.com/paritytech/subxt/issues/1782.
#[subxt_test]
#[ignore]
async fn finalized_headers_subscription() -> Result<(), subxt::Error> {
let ctx = test_context().await;
let api = ctx.client();
Expand Down
1 change: 1 addition & 0 deletions testing/integration-tests/src/full_client/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ async fn partial_fee_estimate_correct() {
}

#[subxt_test]
#[ignore]
async fn legacy_and_unstable_block_subscription_reconnect() {
let ctx = test_context_reconnecting_rpc_client().await;
let api = ctx.unstable_client().await;
Expand Down
18 changes: 9 additions & 9 deletions testing/substrate-runner/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
),
}
}
Expand Down
53 changes: 44 additions & 9 deletions testing/substrate-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -303,5 +306,37 @@ fn try_find_substrate_port_from_output(
}
}

(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()))
}
}
Loading