From 9c76c762cca690284d693ba7fba6209eb148a49d Mon Sep 17 00:00:00 2001 From: Robert Bruce Park Date: Thu, 23 Mar 2017 10:05:21 -0700 Subject: [PATCH] Tweak recurring email frequency. --- britney2/policies/email.py | 10 ++++++---- tests/test_email.py | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/britney2/policies/email.py b/britney2/policies/email.py index a453624..033ea54 100644 --- a/britney2/policies/email.py +++ b/britney2/policies/email.py @@ -28,13 +28,13 @@ BOTS = { MESSAGE = """From: Ubuntu Release Team To: {recipients} X-Proposed-Migration: notice -Subject: [proposed-migration] {source_name} {version} stuck in {series}-proposed for {rounded_age} days. +Subject: [proposed-migration] {source_name} {version} stuck in {series}-proposed for {rounded_age} day{plural}. Hi, {source_name} {version} needs attention. -It has been stuck in {series}-proposed for {rounded_age} days. +It has been stuck in {series}-proposed for {rounded_age} day{plural}. You either sponsored or uploaded this package, please investigate why it hasn't been approved for migration. @@ -158,22 +158,24 @@ class EmailPolicy(BasePolicy, Rest): def apply_policy_impl(self, email_info, suite, source_name, source_data_tdist, source_data_srcdist, excuse): """Send email if package is rejected.""" + max_age = 5 if excuse.is_valid else 1 series = self.options.series version = source_data_srcdist.version age = excuse.daysold or 0 rounded_age = int(age) + plural = '' if rounded_age == 1 else 's' # an item is stuck if it's # - old enough # - not blocked # - not temporarily rejected (e.g. by the autopkgtest policy when tests # are still running) - stuck = age >= 3 and 'block' not in excuse.reason and \ + stuck = age >= max_age and 'block' not in excuse.reason and \ excuse.current_policy_verdict != PolicyVerdict.REJECTED_TEMPORARILY cached = self.cache.get(source_name, {}).get(version) try: emails, sent_age = cached - sent = (age - sent_age) < min(MAX_FREQUENCY, age / 2.0) + sent = (age - sent_age) < min(MAX_FREQUENCY, (age / 2.0) + 0.5) except TypeError: # This exception happens when source_name, version never seen before emails = [] diff --git a/tests/test_email.py b/tests/test_email.py index 1899d9c..fceb2a2 100755 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -225,8 +225,9 @@ class T(unittest.TestCase): @patch('britney2.policies.email.EmailPolicy.lp_get_emails') @patch('britney2.policies.email.smtplib', autospec=True) - def test_smtp_repetition(self, smtp, lp): + def smtp_repetition(self, smtp, lp, valid=False, expected=None): """Resend mails periodically, with decreasing frequency.""" + FakeExcuse.is_valid = valid lp.return_value = ['email@address.com'] sendmail = smtp.SMTP().sendmail e = EmailPolicy(FakeOptions, None) @@ -240,9 +241,19 @@ class T(unittest.TestCase): if sendmail.call_count > previous: e.initialise(None) # Refill e.cache from disk called.append(age) + name, args, kwargs = sendmail.mock_calls[-1] + text = args[2] + self.assertNotIn(' 1 days.', text) + self.assertSequenceEqual(called, expected) + + def test_smtp_repetition(self): + """Confirm that emails are sent at appropriate intervals.""" # Emails were sent when daysold reached these values: - self.assertSequenceEqual(called, [ - 3.0, 6.0, 12.0, 24.0, 48.0, 78.0, 108.0, 138.0, 168.0, 198.0 + self.smtp_repetition(valid=False, expected=[ + 1.0, 3.0, 7.0, 15.0, 31.0, 61.0, 91.0, 121.0, 151.0, 181.0 + ]) + self.smtp_repetition(valid=True, expected=[ + 5.0, 11.0, 23.0, 47.0, 77.0, 107.0, 137.0, 167.0, 197.0 ])