Skip to content

Commit ff2925d

Browse files
committed
test(pgstac): factor out the test mutex
1 parent 853936b commit ff2925d

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

crates/pgstac/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ webpki-roots = { workspace = true, optional = true }
2929

3030
[dev-dependencies]
3131
pgstac-test = { path = "pgstac-test" }
32+
pgstac-test-inner = { path = "pgstac-test-inner" }
3233
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
3334
tokio-test.workspace = true
3435

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "pgstac-test-inner"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use std::sync::Mutex;
2+
3+
pub static MUTEX: Mutex<()> = Mutex::new(());

crates/pgstac/pgstac-test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ fn impl_pgstac_test(ast: ItemFn) -> TokenStream {
1313
let gen = quote! {
1414
#[tokio::test]
1515
async fn #ident() {
16+
use pgstac_test_inner::MUTEX;
17+
1618
let _mutex = MUTEX.lock().unwrap();
1719
let config = std::env::var("PGSTAC_RS_TEST_DB")
1820
.unwrap_or("postgresql://username:password@localhost:5432/postgis".to_string());

crates/pgstac/src/client.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,8 @@ pub(crate) mod tests {
258258
use serde_json::{json, Map};
259259
use stac::{Collection, Item};
260260
use stac_api::{Fields, Filter, Search, Sortby};
261-
use std::sync::Mutex;
262261
use tokio_postgres::Transaction;
263262

264-
// This is an absolutely heinous way to ensure that only one test is hitting
265-
// the DB at a time -- the MUTEX is used in the pgstac-test crate as part of
266-
// the code generated by `pgstac_test`.
267-
//
268-
// There's got to be a better way.
269-
pub(crate) static MUTEX: Mutex<()> = Mutex::new(());
270-
271263
fn longmont() -> Geometry {
272264
Geometry::new(Value::Point(vec![-105.1019, 40.1672]))
273265
}

crates/pgstac/src/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Default for DummyTlsVerifier {
9696

9797
#[cfg(test)]
9898
mod tests {
99-
use crate::client::tests::MUTEX;
99+
use pgstac_test_inner::MUTEX;
100100

101101
#[tokio::test]
102102
async fn connect() {

0 commit comments

Comments
 (0)