mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-24 00:20:37 +00:00
Cleanup
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<Child>,
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user