Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions crates/icp/src/network/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ impl NetworkRootPaths {
pub fn pocketic_port_file(&self) -> PathBuf {
self.pocketic_dir().join("port")
}

/// PocketIC writes its stdout to this file.
pub fn pocketic_stdout_file(&self) -> PathBuf {
self.pocketic_dir().join("stdout.log")
}

/// PocketIC writes its stderr to this file.
pub fn pocketic_stderr_file(&self) -> PathBuf {
self.pocketic_dir().join("stderr.log")
}
}

impl PathsAccess for NetworkRootPaths {
Expand Down
14 changes: 11 additions & 3 deletions crates/icp/src/network/managed/pocketic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,22 @@ pub struct PocketIcInstance {
pub root_key: String,
}

pub fn spawn_pocketic(pocketic_path: &Path, port_file: &Path) -> tokio::process::Child {
pub fn spawn_pocketic(
pocketic_path: &Path,
port_file: &Path,
stdout_file: &Path,
stderr_file: &Path,
) -> tokio::process::Child {
let mut cmd = tokio::process::Command::new(pocketic_path);
cmd.arg("--port-file");
cmd.arg(port_file.as_os_str());
cmd.args(["--ttl", "2592000", "--log-levels", "error"]);

cmd.stdout(std::process::Stdio::inherit());
cmd.stderr(std::process::Stdio::inherit());
let stdout = std::fs::File::create(stdout_file).expect("Failed to create stdout file.");
let stderr = std::fs::File::create(stderr_file).expect("Failed to create stderr file.");
cmd.stdout(std::process::Stdio::from(stdout));
cmd.stderr(std::process::Stdio::from(stderr));

#[cfg(unix)]
{
cmd.process_group(0);
Expand Down
7 changes: 6 additions & 1 deletion crates/icp/src/network/managed/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ async fn run_pocketic(
}
create_dir_all(&root.state_dir()).context(CreateDirAllSnafu)?;

let child = c_child.insert(spawn_pocketic(pocketic_path, &port_file));
let child = c_child.insert(spawn_pocketic(
pocketic_path,
&port_file,
&root.pocketic_stdout_file(),
&root.pocketic_stderr_file(),
));
let pocketic_port = wait_for_port(&port_file, child).await?;
eprintln!("PocketIC started on port {pocketic_port}");
let instance = initialize_pocketic(
Expand Down