Skip to content

Commit

Permalink
test: gracefully shutdown postgres client in sql tests (#3958)
Browse files Browse the repository at this point in the history
* chore: debug log

* test: gracefully shutdown pg client
  • Loading branch information
evenyag authored May 16, 2024
1 parent a45017a commit 669a6d8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests-integration/tests/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ macro_rules! sql_test {
#[$meta]
)*
async fn [< $test >]() {
common_telemetry::init_default_ut_logging();

let store_type = tests_integration::test_util::StorageType::$service;
if store_type.test_on() {
common_telemetry::info!("test {} starts, store_type: {:?}", stringify!($test), store_type);

let _ = $crate::sql::$test(store_type).await;
}

Expand Down Expand Up @@ -427,8 +431,10 @@ pub async fn test_postgres_bytea(store_type: StorageType) {
let (client, connection) = tokio_postgres::connect(&format!("postgres://{addr}/public"), NoTls)
.await
.unwrap();
let (tx, rx) = tokio::sync::oneshot::channel();
tokio::spawn(async move {
connection.await.unwrap();
tx.send(()).unwrap();
});
let _ = client
.simple_query("CREATE TABLE test(b BLOB, ts TIMESTAMP TIME INDEX)")
Expand Down Expand Up @@ -481,6 +487,9 @@ pub async fn test_postgres_bytea(store_type: StorageType) {
let val: Vec<u8> = row.get("b");
assert_eq!(val, [97, 98, 99, 107, 108, 109, 42, 169, 84]);

drop(client);
rx.await.unwrap();

let _ = fe_pg_server.shutdown().await;
guard.remove_all().await;
}
Expand All @@ -492,8 +501,10 @@ pub async fn test_postgres_datestyle(store_type: StorageType) {
.await
.unwrap();

let (tx, rx) = tokio::sync::oneshot::channel();
tokio::spawn(async move {
connection.await.unwrap();
tx.send(()).unwrap();
});

let validate_datestyle = |client: Client, datestyle: &str, is_valid: bool| {
Expand Down Expand Up @@ -703,6 +714,9 @@ pub async fn test_postgres_datestyle(store_type: StorageType) {
}
}

drop(client);
rx.await.unwrap();

let _ = fe_pg_server.shutdown().await;
guard.remove_all().await;
}
Expand All @@ -714,8 +728,10 @@ pub async fn test_postgres_timezone(store_type: StorageType) {
.await
.unwrap();

let (tx, rx) = tokio::sync::oneshot::channel();
tokio::spawn(async move {
connection.await.unwrap();
tx.send(()).unwrap();
});

let get_row = |mess: Vec<SimpleQueryMessage>| -> String {
Expand Down Expand Up @@ -758,6 +774,10 @@ pub async fn test_postgres_timezone(store_type: StorageType) {
.unwrap(),
);
assert_eq!(timezone, "UTC");

drop(client);
rx.await.unwrap();

let _ = fe_pg_server.shutdown().await;
guard.remove_all().await;
}
Expand All @@ -769,8 +789,10 @@ pub async fn test_postgres_parameter_inference(store_type: StorageType) {
.await
.unwrap();

let (tx, rx) = tokio::sync::oneshot::channel();
tokio::spawn(async move {
connection.await.unwrap();
tx.send(()).unwrap();
});

// Create demo table
Expand All @@ -796,6 +818,10 @@ pub async fn test_postgres_parameter_inference(store_type: StorageType) {

assert_eq!(1, rows.len());

// Shutdown the client.
drop(client);
rx.await.unwrap();

let _ = fe_pg_server.shutdown().await;
guard.remove_all().await;
}
Expand Down

0 comments on commit 669a6d8

Please sign in to comment.