MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / pglite_proxy_print_uri_accepts_sqlx_connection

Function pglite_proxy_print_uri_accepts_sqlx_connection

tests/cli_smoke.rs:26–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24
25#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
26async fn pglite_proxy_print_uri_accepts_sqlx_connection() -> Result<()> {
27 let _trace = TestTrace::new("pglite_proxy_print_uri_accepts_sqlx_connection");
28 let process = Command::new(env!("CARGO_BIN_EXE_pglite-proxy"))
29 .args(["--temporary", "--tcp", "127.0.0.1:0", "--print-uri"])
30 .stdout(Stdio::piped())
31 .stderr(Stdio::piped())
32 .spawn()
33 .context("spawn pglite-proxy")?;
34 let mut child = ChildGuard::new(process, "pglite-proxy")?;
35
36 let stdout = child
37 .child_mut()
38 .stdout
39 .take()
40 .context("pglite-proxy stdout pipe")?;
41 let mut reader = BufReader::new(stdout);
42 let mut uri = String::new();
43 let bytes = reader
44 .read_line(&mut uri)
45 .context("read pglite-proxy printed URI")?;
46 if bytes == 0 {
47 let stderr = child.collect_stderr();
48 anyhow::bail!("pglite-proxy exited before printing URI\n\nstderr:\n{stderr}");
49 }
50 let uri = uri.trim();
51 assert!(
52 uri.starts_with("postgresql://") || uri.starts_with("postgres://"),
53 "unexpected URI: {uri}"
54 );
55 trace_step("pglite_proxy printed URI");
56
57 let mut conn = match timeout(Duration::from_secs(30), sqlx::PgConnection::connect(uri)).await {
58 Ok(Ok(conn)) => conn,
59 Ok(Err(err)) => {
60 let stderr = child.collect_stderr();
61 let direct = direct_open_diagnostic();
62 anyhow::bail!(
63 "connect to pglite-proxy failed: {err:#}\n\nstderr:\n{stderr}\n\ndirect backend diagnostic:\n{direct}"
64 );
65 }
66 Err(err) => {
67 let stderr = child.collect_stderr();
68 let direct = direct_open_diagnostic();
69 anyhow::bail!(
70 "timed out connecting to pglite-proxy: {err}\n\nstderr:\n{stderr}\n\ndirect backend diagnostic:\n{direct}"
71 );
72 }
73 };
74 let row = sqlx::query("SELECT $1::int4 + 1 AS answer")
75 .bind(41_i32)
76 .fetch_one(&mut conn)
77 .await?;
78 assert_eq!(row.try_get::<i32, _>("answer")?, 42);
79
80 conn.close().await?;
81 Ok(())
82}

Callers

nothing calls this directly

Calls 7

trace_stepFunction · 0.85
direct_open_diagnosticFunction · 0.85
argsMethod · 0.80
child_mutMethod · 0.80
collect_stderrMethod · 0.80
bindMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected