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

fix: opt-in to keep stdout #1985

Merged
merged 2 commits into from
Feb 1, 2025
Merged
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
14 changes: 13 additions & 1 deletion crates/node-bindings/src/nodes/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub struct Anvil {
fork_block_number: Option<u64>,
args: Vec<OsString>,
timeout: Option<u64>,
keep_stdout: bool,
}

impl Anvil {
Expand Down Expand Up @@ -261,6 +262,14 @@ impl Anvil {
self
}

/// Keep the handle to anvil's stdout in order to read from it.
///
/// Caution: if the stdout handle isn't used, this can end up blocking.
pub const fn keep_stdout(mut self) -> Self {
self.keep_stdout = true;
self
}

/// Consumes the builder and spawns `anvil`.
///
/// # Panics
Expand Down Expand Up @@ -360,7 +369,10 @@ impl Anvil {
}
}

child.stdout = Some(reader.into_inner());
if self.keep_stdout {
// re-attach the stdout handle if requested
child.stdout = Some(reader.into_inner());
}

Ok(AnvilInstance {
child,
Expand Down
15 changes: 14 additions & 1 deletion crates/node-bindings/src/nodes/reth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub struct Reth {
chain_or_path: Option<String>,
genesis: Option<Genesis>,
args: Vec<OsString>,
keep_stdout: bool,
}

impl Reth {
Expand All @@ -187,6 +188,7 @@ impl Reth {
chain_or_path: None,
genesis: None,
args: Vec::new(),
keep_stdout: false,
}
}

Expand Down Expand Up @@ -309,6 +311,14 @@ impl Reth {
self
}

/// Keep the handle to reth's stdout in order to read from it.
///
/// Caution: if the stdout handle isn't used, this can end up blocking.
pub const fn keep_stdout(mut self) -> Self {
self.keep_stdout = true;
self
}

/// Adds an argument to pass to `reth`.
///
/// Pass any arg that is not supported by the builder.
Expand Down Expand Up @@ -510,7 +520,10 @@ impl Reth {
}
}

child.stdout = Some(reader.into_inner());
if self.keep_stdout {
// re-attach the stdout handle if requested
child.stdout = Some(reader.into_inner());
}

Ok(RethInstance {
pid: child,
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ mod tests {

#[tokio::test]
async fn capture_anvil_logs() {
let mut anvil = Anvil::new().spawn();
let mut anvil = Anvil::new().keep_stdout().spawn();

let provider = ProviderBuilder::new().on_http(anvil.endpoint_url());

Expand Down