Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Improve duplicate email assertion message
Browse files Browse the repository at this point in the history
Summary:
* Save build id in the email event
* Show collection and build ids in assertion message

With these changes we can see which build triggered the successful
email, and which one caused the failure.

Test Plan: Unit tests

Reviewers: vishal

Reviewed By: vishal

Subscribers: changesbot, dfb-reviews, reviews-dfbgrowth, christoffer

Differential Revision: https://tails.corp.dropbox.com/D92024
  • Loading branch information
kajic committed Feb 25, 2015
1 parent 6b68f15 commit 417aec3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions changes/listeners/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,23 @@ def aggregate_count(items, key):
class MailNotificationHandler(object):
logger = logging.getLogger('mail')

def send(self, msg, collection_id):
def send(self, msg, build):
if not msg.recipients:
self.logger.info('Exiting for collection_id={} because its message has no recipients.'.format(collection_id))
self.logger.info(
'Exiting for collection_id={} because its message has no '
'recipients.'.format(build.collection_id))
return

event = try_create(Event, where={
'type': EventType.email,
'item_id': collection_id,
'item_id': build.collection_id,
'data': {
'triggering_build_id': build.id.hex,
'recipients': msg.recipients,
}
})
assert event, 'An email has already been sent for this build collection.'
assert event, 'An email has already been sent for collection_id={} (build_id={}).'.format(
build.collection_id, build.id.hex)

mail.send(msg)

Expand Down Expand Up @@ -425,4 +429,4 @@ def build_finished_handler(build_id, *args, **kwargs):
msg = notification_handler.get_msg(context)

if context['result'] != Result.passed:
notification_handler.send(msg, build.collection_id)
notification_handler.send(msg, build)
6 changes: 3 additions & 3 deletions tests/changes/listeners/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_simple(self, get_collection_recipients):
handler = MailNotificationHandler()
context = handler.get_collection_context([build])
msg = handler.get_msg(context)
handler.send(msg, build.collection_id)
handler.send(msg, build)

assert len(self.outbox) == 1
msg = self.outbox[0]
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_subject_branch(self, get_collection_recipients):
handler = MailNotificationHandler()
context = handler.get_collection_context([build])
msg = handler.get_msg(context)
handler.send(msg, build.collection_id)
handler.send(msg, build)

assert len(self.outbox) == 1
msg = self.outbox[0]
Expand Down Expand Up @@ -257,7 +257,7 @@ def test_multiple_sources(self, get_collection_recipients):
handler = MailNotificationHandler()
context = handler.get_collection_context([build])
msg = handler.get_msg(context)
handler.send(msg, build.collection_id)
handler.send(msg, build)

assert len(self.outbox) == 1
msg = self.outbox[0]
Expand Down

0 comments on commit 417aec3

Please sign in to comment.