Skip to content

Commit ba56010

Browse files
committed
pg: test prepared statement reuse
1 parent 50491dd commit ba56010

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

impls/src/postgres_store.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ where
842842
#[cfg(test)]
843843
mod tests {
844844
use super::{
845-
decode_page_token, drop_database, encode_page_token, DUMMY_MIGRATION,
845+
decode_page_token, drop_database, encode_page_token, Client, DUMMY_MIGRATION,
846846
INITIAL_RECORD_VERSION_STR, MIGRATIONS,
847847
};
848848
use crate::postgres_store::PostgresPlaintextBackend;
@@ -1268,6 +1268,21 @@ mod tests {
12681268
assert_eq!(&INITIAL_RECORD_VERSION.to_string(), INITIAL_RECORD_VERSION_STR);
12691269
}
12701270

1271+
#[tokio::test]
1272+
async fn prepared_statements_are_reused_across_transactions() {
1273+
let mut conn = Client::connect(&POSTGRES_ENDPOINT, DEFAULT_DB, NoTls).await.unwrap();
1274+
let stmt = "SELECT $1::BIGINT";
1275+
1276+
let mut transaction = conn.transaction().await.unwrap();
1277+
transaction.execute(stmt, &[&1_i64]).await.unwrap();
1278+
transaction.commit().await.unwrap();
1279+
assert_eq!(conn.statement_cache.statements.len(), 1);
1280+
1281+
let rows = conn.query(stmt, &[&2_i64]).await.unwrap();
1282+
assert_eq!(rows[0].get::<_, i64>(0), 2);
1283+
assert_eq!(conn.statement_cache.statements.len(), 1);
1284+
}
1285+
12711286
#[test]
12721287
fn page_token_roundtrips() {
12731288
let token = encode_page_token(12345);

0 commit comments

Comments
 (0)