Skip to content

Commit 49a6430

Browse files
committed
Add test for max_backend_message_size
1 parent 9461613 commit 49a6430

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tokio-postgres/src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ impl Config {
599599
self.replication_mode(mode);
600600
}
601601
}
602+
"max_backend_message_size" => {
603+
let limit = value
604+
.parse::<usize>()
605+
.map_err(|_| Error::config_parse(Box::new(InvalidValue("max_backend_message_size"))))?;
606+
if limit > 0 {
607+
self.max_backend_message_size(limit);
608+
}
609+
}
602610
key => {
603611
return Err(Error::config_parse(Box::new(UnknownOption(
604612
key.to_string(),

tokio-postgres/tests/test/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,30 @@ async fn query_raw_txt() {
280280
assert!(rows[0].body_len() > 0);
281281
}
282282

283+
#[tokio::test]
284+
async fn limit_max_backend_message_size() {
285+
let client = connect("user=postgres max_backend_message_size=10000").await;
286+
let small: Vec<tokio_postgres::Row> = client
287+
.query_raw_txt("SELECT REPEAT('a', 20)", [])
288+
.await
289+
.unwrap()
290+
.try_collect()
291+
.await
292+
.unwrap();
293+
294+
assert_eq!(small.len(), 1);
295+
assert_eq!(small[0].as_text(0).unwrap().unwrap().len(), 20);
296+
297+
let large: Result<Vec<tokio_postgres::Row>, Error> = client
298+
.query_raw_txt("SELECT REPEAT('a', 2000000)", [])
299+
.await
300+
.unwrap()
301+
.try_collect()
302+
.await;
303+
304+
assert!(large.is_err());
305+
}
306+
283307
#[tokio::test]
284308
async fn command_tag() {
285309
let client = connect("user=postgres").await;

0 commit comments

Comments
 (0)