Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

test_push_notifications: Close event loops.

Anders Kaseorg9e70a47f93ad
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index fb6f63eb019..c883344be98 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -849,9 +849,12 @@ class PushNotificationTest(BouncerTestCase):
@contextmanager
def mock_apns(self) -> Iterator[APNsContext]:
apns_context = APNsContext(apns=mock.Mock(), loop=asyncio.new_event_loop())
- with mock.patch("zerver.lib.push_notifications.get_apns_context") as mock_get:
- mock_get.return_value = apns_context
- yield apns_context
+ try:
+ with mock.patch("zerver.lib.push_notifications.get_apns_context") as mock_get:
+ mock_get.return_value = apns_context
+ yield apns_context
+ finally:
+ apns_context.loop.close()
def setup_apns_tokens(self) -> None:
self.tokens = ["aaaa", "bbbb"]
@@ -1457,7 +1460,10 @@ class TestAPNs(PushNotificationTest):
with self.settings(APNS_CERT_FILE="/foo.pem"), mock.patch("aioapns.APNs") as mock_apns:
apns_context = get_apns_context()
assert apns_context is not None
- self.assertEqual(mock_apns.return_value, apns_context.apns)
+ try:
+ self.assertEqual(mock_apns.return_value, apns_context.apns)
+ finally:
+ apns_context.loop.close()
finally:
# Reset the cache for `get_apns_context` so that we don't
# leak changes to the rest of the world.