Add test for DB disconnects while waiting for notifications

This commit is contained in:
Johannes Schriewer 2018-01-30 15:32:43 +01:00
parent 75527beacf
commit 5171cbeca0

View File

@ -901,6 +901,30 @@ fn test_notification_next_timeout() {
assert!(it.next().unwrap().is_none()); assert!(it.next().unwrap().is_none());
} }
#[test]
fn test_notification_disconnect() {
let conn = or_panic!(Connection::connect(
"postgres://postgres@localhost:5433",
TlsMode::None,
));
or_panic!(conn.execute("LISTEN test_notifications_disconnect", &[]));
let _t = thread::spawn(|| {
let conn = or_panic!(Connection::connect(
"postgres://postgres@localhost:5433",
TlsMode::None,
));
thread::sleep(Duration::from_millis(500));
or_panic!(conn.execute(
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE query = 'LISTEN test_notifications_disconnect'",
&[],
));
});
let notifications = conn.notifications();
assert!(notifications.blocking_iter().next().is_err());
}
#[test] #[test]
// This test is pretty sad, but I don't think there's a better way :( // This test is pretty sad, but I don't think there's a better way :(
fn test_cancel_query() { fn test_cancel_query() {