diff --git a/postgresql_archive/tests/zonky.rs b/postgresql_archive/tests/zonky.rs index 8ee54b2..af8ee90 100644 --- a/postgresql_archive/tests/zonky.rs +++ b/postgresql_archive/tests/zonky.rs @@ -42,14 +42,7 @@ async fn test_get_archive_and_extract() -> anyhow::Result<()> { let out_dir = tempfile::tempdir()?.path().to_path_buf(); let files = extract(url, &archive, &out_dir).await?; - #[cfg(all(target_os = "linux", target_arch = "x86_64"))] - assert_eq!(1_023, files.len()); - #[cfg(all(target_os = "macos", target_arch = "aarch64"))] - assert_eq!(1_021, files.len()); - #[cfg(all(target_os = "macos", target_arch = "x86_64"))] - assert_eq!(1_021, files.len()); - #[cfg(all(target_os = "windows", target_arch = "x86_64"))] - assert_eq!(1_021, files.len()); + assert!(files.len() > 1_000); remove_dir_all(&out_dir)?; Ok(()) } diff --git a/postgresql_commands/src/traits.rs b/postgresql_commands/src/traits.rs index dbd6df5..e688d0e 100644 --- a/postgresql_commands/src/traits.rs +++ b/postgresql_commands/src/traits.rs @@ -183,34 +183,38 @@ impl AsyncCommandExecutor for tokio::process::Command { /// Execute the command and return the stdout and stderr async fn execute(&mut self, timeout: Option) -> Result<(String, String)> { debug!("Executing command: {}", self.to_command_string()); - let output = match timeout { - Some(duration) => tokio::time::timeout(duration, self.output()).await?, - None => self.output().await, - }?; let program = self.as_std().get_program().to_string_lossy().to_string(); let stdout: String; let stderr: String; + let status: ExitStatus; if OS == "windows" && program.as_str().ends_with("pg_ctl") { // The pg_ctl process can hang on Windows when attempting to get stdout/stderr. + let mut process = self + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .spawn()?; stdout = String::new(); stderr = String::new(); + status = process.wait().await?; } else { + let output = match timeout { + Some(duration) => tokio::time::timeout(duration, self.output()).await?, + None => self.output().await, + }?; stdout = String::from_utf8_lossy(&output.stdout).into_owned(); stderr = String::from_utf8_lossy(&output.stderr).into_owned(); + status = output.status; } debug!( "Result: {}\nstdout: {}\nstderr: {}", - output - .status - .code() - .map_or("None".to_string(), |c| c.to_string()), + status.code().map_or("None".to_string(), |c| c.to_string()), stdout, stderr ); - if output.status.success() { + if status.success() { Ok((stdout, stderr)) } else { Err(Error::CommandError { stdout, stderr })