Skip to content

Commit e6753a1

Browse files
authored
butane_test_helper: Enhancements to improve API & testing (#363)
1 parent 584e378 commit e6753a1

File tree

4 files changed

+198
-35
lines changed

4 files changed

+198
-35
lines changed

Cargo.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

butane_test_helper/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ documentation = "https://docs.rs/butane/"
1313
rust-version.workspace = true
1414

1515
[features]
16+
bin = ["ctrlc"]
1617
default = ["sqlite", "pg"]
1718
sqlite = ["butane_core/sqlite", "butane_core/async-adapter"]
1819
sqlite-bundled = ["butane_core/sqlite-bundled"]
@@ -21,15 +22,24 @@ pg = ["butane_core/pg", "tokio-postgres"]
2122
[dependencies]
2223
block-id = "0.2"
2324
butane_core = { workspace = true }
25+
ctrlc = { version = "3.4", optional = true }
2426
env_logger.workspace = true
2527
libc = "0.2"
2628
log.workspace = true
2729
maybe-async-cfg.workspace = true
2830
nonempty.workspace = true
31+
thiserror.workspace = true
2932
tokio-postgres = { features = ["with-geo-types-0_7"], optional = true, workspace = true }
3033
rand.workspace = true
3134
tempfile.workspace = true
3235
uuid = { features = ["v4"], workspace = true }
3336

3437
[package.metadata.release]
3538
release = false
39+
40+
[[bin]]
41+
bench = false
42+
name = "pg_tmp_server"
43+
path = "src/bin/pg_tmp_server.rs"
44+
required-features = ["bin", "pg"]
45+
test = false
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::sync::atomic::{AtomicBool, Ordering};
2+
use std::sync::Arc;
3+
4+
use butane_test_helper::{pg_tmp_server_create, PgServerOptions};
5+
6+
fn main() {
7+
// Start the PostgreSQL server
8+
let server = pg_tmp_server_create(PgServerOptions {
9+
port: Some(5432),
10+
..Default::default()
11+
})
12+
.unwrap();
13+
// Print the connection string
14+
println!(
15+
"Running temporary PostgreSQL server\nUnix socket dir: {}\nUser: postgres",
16+
server.sockdir.path().display()
17+
);
18+
19+
let running = Arc::new(AtomicBool::new(true));
20+
let r = running.clone();
21+
22+
ctrlc::set_handler(move || {
23+
r.store(false, Ordering::SeqCst);
24+
})
25+
.expect("Error setting Ctrl-C handler");
26+
27+
println!("Waiting for Ctrl-C...");
28+
while running.load(Ordering::SeqCst) {}
29+
println!("Exiting...");
30+
}

0 commit comments

Comments
 (0)