Skip to content

Commit 5171cbe

Browse files
committed
Add test for DB disconnects while waiting for notifications
1 parent 75527be commit 5171cbe

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

postgres/tests/test.rs

+24
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,30 @@ fn test_notification_next_timeout() {
901901
assert!(it.next().unwrap().is_none());
902902
}
903903

904+
#[test]
905+
fn test_notification_disconnect() {
906+
let conn = or_panic!(Connection::connect(
907+
"postgres://postgres@localhost:5433",
908+
TlsMode::None,
909+
));
910+
or_panic!(conn.execute("LISTEN test_notifications_disconnect", &[]));
911+
912+
let _t = thread::spawn(|| {
913+
let conn = or_panic!(Connection::connect(
914+
"postgres://postgres@localhost:5433",
915+
TlsMode::None,
916+
));
917+
thread::sleep(Duration::from_millis(500));
918+
or_panic!(conn.execute(
919+
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE query = 'LISTEN test_notifications_disconnect'",
920+
&[],
921+
));
922+
});
923+
924+
let notifications = conn.notifications();
925+
assert!(notifications.blocking_iter().next().is_err());
926+
}
927+
904928
#[test]
905929
// This test is pretty sad, but I don't think there's a better way :(
906930
fn test_cancel_query() {

0 commit comments

Comments
 (0)