Skip to content

Commit 7ef29da

Browse files
Merge pull request #153 from theseus-rs/spawn-pg-ctl-on-windows-async
fix: use tokio::process::spawn() for pc_ctl on Windows
2 parents 01977bd + e93b944 commit 7ef29da

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

postgresql_archive/tests/zonky.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ async fn test_get_archive_and_extract() -> anyhow::Result<()> {
4242

4343
let out_dir = tempfile::tempdir()?.path().to_path_buf();
4444
let files = extract(url, &archive, &out_dir).await?;
45-
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
46-
assert_eq!(1_023, files.len());
47-
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
48-
assert_eq!(1_021, files.len());
49-
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
50-
assert_eq!(1_021, files.len());
51-
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
52-
assert_eq!(1_021, files.len());
45+
assert!(files.len() > 1_000);
5346
remove_dir_all(&out_dir)?;
5447
Ok(())
5548
}

postgresql_commands/src/traits.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,34 +183,38 @@ impl AsyncCommandExecutor for tokio::process::Command {
183183
/// Execute the command and return the stdout and stderr
184184
async fn execute(&mut self, timeout: Option<Duration>) -> Result<(String, String)> {
185185
debug!("Executing command: {}", self.to_command_string());
186-
let output = match timeout {
187-
Some(duration) => tokio::time::timeout(duration, self.output()).await?,
188-
None => self.output().await,
189-
}?;
190186
let program = self.as_std().get_program().to_string_lossy().to_string();
191187
let stdout: String;
192188
let stderr: String;
189+
let status: ExitStatus;
193190

194191
if OS == "windows" && program.as_str().ends_with("pg_ctl") {
195192
// The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
193+
let mut process = self
194+
.stdout(std::process::Stdio::piped())
195+
.stderr(std::process::Stdio::piped())
196+
.spawn()?;
196197
stdout = String::new();
197198
stderr = String::new();
199+
status = process.wait().await?;
198200
} else {
201+
let output = match timeout {
202+
Some(duration) => tokio::time::timeout(duration, self.output()).await?,
203+
None => self.output().await,
204+
}?;
199205
stdout = String::from_utf8_lossy(&output.stdout).into_owned();
200206
stderr = String::from_utf8_lossy(&output.stderr).into_owned();
207+
status = output.status;
201208
}
202209

203210
debug!(
204211
"Result: {}\nstdout: {}\nstderr: {}",
205-
output
206-
.status
207-
.code()
208-
.map_or("None".to_string(), |c| c.to_string()),
212+
status.code().map_or("None".to_string(), |c| c.to_string()),
209213
stdout,
210214
stderr
211215
);
212216

213-
if output.status.success() {
217+
if status.success() {
214218
Ok((stdout, stderr))
215219
} else {
216220
Err(Error::CommandError { stdout, stderr })

0 commit comments

Comments
 (0)