(&mut self, log_path: &Path)
| 3418 | } |
| 3419 | |
| 3420 | fn wait_ready(&mut self, log_path: &Path) -> Result<()> { |
| 3421 | #[cfg(unix)] |
| 3422 | let socket_path = self.socket_dir.join(format!(".s.PGSQL.{}", self.port)); |
| 3423 | let start = Instant::now(); |
| 3424 | let runtime = tokio::runtime::Builder::new_current_thread() |
| 3425 | .enable_all() |
| 3426 | .build() |
| 3427 | .context("create native Postgres readiness Tokio runtime")?; |
| 3428 | let mut last_probe_error = None; |
| 3429 | while start.elapsed() < Duration::from_secs(15) { |
| 3430 | if let Some(status) = self.child.try_wait().context("poll native postgres")? { |
| 3431 | let log = fs::read_to_string(log_path).unwrap_or_default(); |
| 3432 | bail!("native postgres exited early with {status}; log:\n{log}"); |
| 3433 | } |
| 3434 | #[cfg(unix)] |
| 3435 | let transport_ready = socket_path.exists(); |
| 3436 | #[cfg(not(unix))] |
| 3437 | let transport_ready = true; |
| 3438 | if transport_ready { |
| 3439 | match runtime.block_on(self.probe_ready()) { |
| 3440 | Ok(()) => return Ok(()), |
| 3441 | Err(err) => last_probe_error = Some(err), |
| 3442 | } |
| 3443 | } |
| 3444 | std::thread::sleep(Duration::from_millis(25)); |
| 3445 | } |
| 3446 | let log = fs::read_to_string(log_path).unwrap_or_default(); |
| 3447 | let probe = last_probe_error |
| 3448 | .map(|err| format!("last readiness probe error: {err}\n")) |
| 3449 | .unwrap_or_default(); |
| 3450 | bail!("native postgres did not become ready; {probe}log:\n{log}"); |
| 3451 | } |
| 3452 | |
| 3453 | async fn probe_ready(&self) -> Result<()> { |
| 3454 | let mut config = tokio_postgres::Config::new(); |
no test coverage detected