Remove test query from init code. Seems like PGlite doesn't do error handling correctly. Connection simply drops out as "closed".

This commit is contained in:
Sebastian Jeltsch
2026-05-05 20:37:07 +02:00
parent 65a60af77c
commit c299b0d6cb
3 changed files with 68 additions and 25 deletions
+3 -3
View File
@@ -524,11 +524,11 @@ pub async fn test_state(options: Option<TestStateOptions>) -> anyhow::Result<App
let data_dir = DataDir(temp_dir.path().to_path_buf());
// Start PgLite.
let tcp = true;
let tcp = false;
let (pg_uri, db) = if tcp {
let db = pglite_oxide::PgliteServer::builder()
// .fresh_temporary()
.temporary()
.fresh_temporary()
// .temporary()
.start()?;
(db.connection_uri(), db)
+39 -11
View File
@@ -343,17 +343,21 @@ async fn init_db<'a>(
}
})?;
conn
.read_query_rows(
"
SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name;
",
(),
)
.await
.unwrap();
// TODO: Remove sanity check.
conn.read_query_rows("SELECT 5", ()).await.unwrap();
// WARNING: This makes the connection drop out. Either a permissions thing or with pglite.
// conn
// .read_query_rows(
// "
// SELECT table_schema,table_name
// FROM information_schema.tables
// ORDER BY table_schema,table_name;
// ",
// (),
// )
// .await
// .unwrap();
// Apply migrations.
//
@@ -552,3 +556,27 @@ pub(crate) fn connect_rusqlite_without_default_extensions_and_schemas(
}
const PREPARED_STATEMENT_CACHE_CAPACITY: usize = 256;
#[cfg(all(test, feature = "pg"))]
mod tests {
use pglite_oxide::PgliteServer;
use trailbase_sqlite::Connection;
#[tokio::test]
async fn generic_connection_w_pg_test() {
let db = PgliteServer::temporary_tcp().unwrap();
let pg_uri = db.connection_uri();
println!("Started PgLite: {pg_uri}");
let conn = Connection::pg_with_opts(trailbase_sqlite::generic::PgOptions {
connection: trailbase_sqlite::generic::PgConnection::Uri(pg_uri),
num_threads: Some(1),
})
.unwrap();
// IMPORTANT: PgLite only handles a single concurrent connection.
assert_eq!(1, conn.threads());
conn.read_query_rows("SELECT 5", ()).await.unwrap();
}
}
+26 -11
View File
@@ -101,10 +101,8 @@ impl Connection {
return Ok(Self::new(Executor::Pg(Arc::new(
crate::pg::executor::Executor::new(
move || -> Result<Client, Error> {
match &opts.connection {
PgConnection::Uri(uri) => {
return Ok(Client::connect(uri, NoTls)?);
}
return match &opts.connection {
PgConnection::Uri(uri) => Ok(Client::connect(uri, NoTls)?),
PgConnection::Host {
host,
port,
@@ -125,9 +123,9 @@ impl Connection {
conf.password(pw);
}
return Ok(conf.connect(NoTls)?);
Ok(conf.connect(NoTls)?)
}
}
};
},
crate::pg::executor::Options {
num_threads: opts.num_threads,
@@ -236,7 +234,7 @@ impl Connection {
) -> Result<Rows, Error> {
return match self.exec {
Executor::Sqlite(ref exec) => exec.read_query_rows_f(sql, params, sqlite_from_rows).await,
Executor::Pg(_) => self.write_query_rows(sql, params).await,
Executor::Pg(ref exec) => exec.query_rows_f(sql, params, pg_from_rows).await,
};
}
@@ -714,10 +712,7 @@ mod tests {
return Ok((
db,
PgExecutor::new(
move || {
let conn = Client::connect(&pg_uri, NoTls);
return conn;
},
move || Client::connect(&pg_uri, NoTls),
crate::pg::executor::Options {
// IMPORTANT: PgLite only handles a single concurrent connection.
num_threads: Some(1),
@@ -774,4 +769,24 @@ mod tests {
assert_eq!(count0, count1);
}
#[tokio::test]
async fn generic_connection_w_pg_test() {
let db = PgliteServer::temporary_tcp().unwrap();
let pg_uri = db.connection_uri();
println!("Started PgLite: {pg_uri}");
let conn = Connection::pg_with_opts(PgOptions {
connection: PgConnection::Uri(pg_uri),
num_threads: Some(1),
})
.unwrap();
// IMPORTANT: PgLite only handles a single concurrent connection.
assert_eq!(1, conn.threads());
let rows = conn.read_query_rows("SELECT 5", ()).await.unwrap();
let n: i64 = rows.get(0).unwrap().get(0).unwrap();
assert_eq!(5, n);
}
}