push_notifications: Drop error messages from failure to send.

We handle, and possibly log, these errors ourselves.
This commit is contained in:
Alex Vandiver 2023-08-28 22:43:51 +00:00 committed by Tim Abbott
parent 733c6da298
commit 69825cd54c
2 changed files with 14 additions and 5 deletions

View File

@ -135,10 +135,6 @@ def get_apns_context() -> Optional[APNsContext]:
# import time.
import aioapns
# aioapns logs at "error" level for every non-successful request,
# which fills the logs; see https://github.com/Fatal1ty/aioapns/issues/15
logging.getLogger("aioapns").setLevel(logging.CRITICAL)
if settings.APNS_CERT_FILE is None: # nocoverage
return None
@ -147,12 +143,22 @@ def get_apns_context() -> Optional[APNsContext]:
# hammered with a ton of these all at once after startup.
loop = asyncio.new_event_loop()
# Defining a no-op error-handling function overrides the default
# behaviour of logging at ERROR level whenever delivery fails; we
# handle those errors by checking the result in
# send_apple_push_notification.
async def err_func(
request: aioapns.NotificationRequest, result: aioapns.common.NotificationResult
) -> None:
pass # nocoverage
async def make_apns() -> aioapns.APNs:
return aioapns.APNs(
client_cert=settings.APNS_CERT_FILE,
topic=settings.APNS_TOPIC,
max_connection_attempts=APNS_MAX_RETRIES,
use_sandbox=settings.APNS_SANDBOX,
err_func=err_func,
)
apns = loop.run_until_complete(make_apns())

View File

@ -999,7 +999,10 @@ class PushNotificationTest(BouncerTestCase):
def mock_apns(self) -> Iterator[Tuple[APNsContext, mock.AsyncMock]]:
apns = mock.Mock(spec=aioapns.APNs)
apns.send_notification = mock.AsyncMock()
apns_context = APNsContext(apns=apns, loop=asyncio.new_event_loop())
apns_context = APNsContext(
apns=apns,
loop=asyncio.new_event_loop(),
)
try:
with mock.patch("zerver.lib.push_notifications.get_apns_context") as mock_get:
mock_get.return_value = apns_context