From fe1b471cfc67b448a1e5f5f3ac3f5a77637c4b86 Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Thu, 18 Aug 2022 13:14:05 -0400 Subject: [PATCH] Cleanup --- integration_tests/src/basic.rs | 3 +-- libs/pg_bin/src/lib.rs | 27 ++++++++++----------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/integration_tests/src/basic.rs b/integration_tests/src/basic.rs index 7eb968ef96..5b663209b7 100644 --- a/integration_tests/src/basic.rs +++ b/integration_tests/src/basic.rs @@ -4,7 +4,6 @@ mod tests { use tokio_postgres::NoTls; use pg_bin::LocalPostgres; - use pg_bin::PgProtocol; #[tokio::test] async fn test_postgres_select_1() -> anyhow::Result<()> { @@ -15,7 +14,7 @@ mod tests { // Get a postgres let mut postgres = LocalPostgres::new(pg_datadir, pg_prefix); postgres.start(); - let config = postgres.conn_info(); + let config = postgres.admin_conn_info(); if let Err(e) = config.connect(NoTls).await { eprintln!("error error {:?}", e); diff --git a/libs/pg_bin/src/lib.rs b/libs/pg_bin/src/lib.rs index 0fb78940af..3febee7f3b 100644 --- a/libs/pg_bin/src/lib.rs +++ b/libs/pg_bin/src/lib.rs @@ -2,16 +2,11 @@ use std::{fs::{File, remove_dir_all}, path::PathBuf, process::{Child, Command, Stdio}, time::Duration}; use std::io::Write; -// TODO put these in a different mod -type Port = u16; -pub trait PgProtocol { - fn conn_info(&self) -> tokio_postgres::Config; -} pub struct LocalPostgres { datadir: PathBuf, pg_prefix: PathBuf, - port: Port, + port: u16, running: Option, } @@ -56,18 +51,8 @@ impl LocalPostgres { std::thread::sleep(Duration::from_millis(300)); } -} -impl Drop for LocalPostgres { - fn drop(&mut self) { - if let Some(mut child) = self.running.take() { - child.kill().expect("failed to kill child"); - } - } -} - -impl PgProtocol for LocalPostgres { - fn conn_info(&self) -> tokio_postgres::Config { + pub fn admin_conn_info(&self) -> tokio_postgres::Config { // I don't like this, but idk what else to do let whoami = Command::new("whoami").output().unwrap().stdout; let user = String::from_utf8_lossy(&whoami); @@ -82,3 +67,11 @@ impl PgProtocol for LocalPostgres { config } } + +impl Drop for LocalPostgres { + fn drop(&mut self) { + if let Some(mut child) = self.running.take() { + child.kill().expect("failed to kill child"); + } + } +}