Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lun4m committed Jul 1, 2024
1 parent 4b73813 commit a2e3b04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion integration_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ end_to_end: _end_to_end clean
_end_to_end: setup
cargo test --test end_to_end --no-fail-fast -- --nocapture --test-threads=1

# pass TEST=... make debug_test
# With the `debug` feature, the database is not cleaned up after running the test,
# so it can be inspected with psql. Run with:
# TEST=<name> make debug_test
debug_test: setup
cargo test "$(TEST)" --features debug --no-fail-fast -- --nocapture --test-threads=1

Expand Down
28 changes: 14 additions & 14 deletions integration_tests/tests/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ pub fn mock_permit_tables() -> Arc<RwLock<(ParamPermitTable, StationPermitTable)

let station_permit = HashMap::from([
// station_id -> permit_id
(10000, 1), // potentially overidden by param_permit
(10001, 0), // potentially overidden by param_permit
(10000, 1), // overridden by param_permit
(10001, 0), // overridden by param_permit
(20000, 0),
(20001, 1),
(20002, 1),
Expand All @@ -175,17 +175,7 @@ fn test_timeseries_is_open(station_id: i32, type_id: i32, permit_id: i32) -> boo
timeseries_is_open(permit_tables, station_id, type_id, permit_id).unwrap()
}

pub async fn cleanup() {
let (client, conn) = tokio_postgres::connect(CONNECT_STRING, NoTls)
.await
.unwrap();

tokio::spawn(async move {
if let Err(e) = conn.await {
eprintln!("{}", e);
}
});

pub async fn cleanup(client: &tokio_postgres::Client) {
client
.batch_execute(
// TODO: should clean public.timeseries_id_seq too? RESTART IDENTITY CASCADE?
Expand All @@ -203,14 +193,24 @@ async fn e2e_test_wrapper<T: Future<Output = ()>>(test: T) {
mock_permit_tables(),
));

let (client, conn) = tokio_postgres::connect(CONNECT_STRING, NoTls)
.await
.unwrap();

tokio::spawn(async move {
if let Err(e) = conn.await {
eprintln!("{}", e);
}
});

tokio::select! {
_ = api_server => panic!("API server task terminated first"),
_ = ingestor => panic!("Ingestor server task terminated first"),
// Clean up database even if test panics, to avoid test poisoning
test_result = AssertUnwindSafe(test).catch_unwind() => {
// For debugging a specific test, it might be useful to avoid cleaning up
#[cfg(not(feature = "debug"))]
cleanup().await;
cleanup(&client).await;
assert!(test_result.is_ok())
}
}
Expand Down

0 comments on commit a2e3b04

Please sign in to comment.