From 5171cbeca019c6de599a9310fc4348092aebdc26 Mon Sep 17 00:00:00 2001 From: Johannes Schriewer Date: Tue, 30 Jan 2018 15:32:43 +0100 Subject: [PATCH] Add test for DB disconnects while waiting for notifications --- postgres/tests/test.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/postgres/tests/test.rs b/postgres/tests/test.rs index f62c53bc..84e17dde 100644 --- a/postgres/tests/test.rs +++ b/postgres/tests/test.rs @@ -901,6 +901,30 @@ fn test_notification_next_timeout() { 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] // This test is pretty sad, but I don't think there's a better way :( fn test_cancel_query() {