From 934bcb919f936fc7ced8d8b30dddcbca489d427f Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Tue, 21 May 2019 17:09:16 +0100 Subject: [PATCH] Reduce timeout to 45 seconds following analysis by Chris H-S: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Failure is slower than success. So the longer a notification takes to get a status, the more likely it is for that status to be a failure anyway. This increases dramatically after 45 seconds. The percentage of emails that go to delivered in less than 90 seconds is 98.92%. To get to 99% we’d need to increase the timeout to 178 seconds (3 minutes). We could still get 98.7% of notifications by dropping the timeout to 45 seconds, and improve the experience for notifications that are likely to fail by returning an error more quickly." --- app/main/views/service_settings.py | 2 +- tests/app/main/views/test_service_settings.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 6ed2a90f6..272a171a0 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -481,7 +481,7 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id): created_at_no_tz = notification["created_at"][:-6] seconds_since_sending = (datetime.utcnow() - datetime.strptime(created_at_no_tz, '%Y-%m-%dT%H:%M:%S.%f')).seconds if notification["status"] in FAILURE_STATUSES or ( - notification["status"] in SENDING_STATUSES and seconds_since_sending > 90 + notification["status"] in SENDING_STATUSES and seconds_since_sending > 45 ): verification_status = "failure" form.email_address.data = notification['to'] diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index fa3cb7ec9..0bb1af038 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -2088,7 +2088,7 @@ def test_service_verify_reply_to_address( @freeze_time("2018-06-01 11:11:00.061258") -def test_add_reply_to_email_address_fails_if_notification_not_delivered_in_5_mins(mocker, client_request, fake_uuid): +def test_add_reply_to_email_address_fails_if_notification_not_delivered_in_45_sec(mocker, client_request, fake_uuid): notification = { "id": fake_uuid, "status": "sending", @@ -2096,7 +2096,7 @@ def test_add_reply_to_email_address_fails_if_notification_not_delivered_in_5_min "service_id": SERVICE_ONE_ID, "template_id": TEMPLATE_ONE_ID, "notification_type": "email", - "created_at": '2018-06-01T11:05:52.499230+00:00' + "created_at": '2018-06-01T11:10:12.499230+00:00' } mocker.patch( 'app.service_api_client.get_reply_to_email_addresses', return_value=[] @@ -2112,7 +2112,6 @@ def test_add_reply_to_email_address_fails_if_notification_not_delivered_in_5_min expected_banner = page.find_all('div', class_='banner-dangerous')[0] assert 'There’s a problem with your reply-to address' in expected_banner.text.strip() mock_add_reply_to_email_address.assert_not_called() - # add check that form is visible @pytest.mark.parametrize('fixture, data, api_default_args', [