Merge lp:~frankban/launchpad/bug-1015318 into lp:launchpad

Proposed by Francesco Banconi on 2012-06-22
Status: Merged
Approved by: Graham Binns on 2012-06-22
Approved revision: no longer in the source branch.
Merged at revision: 15474
Proposed branch: lp:~frankban/launchpad/bug-1015318
Merge into: lp:launchpad
Diff against target: 21 lines (+6/-3)
1 file modified
lib/lp/codehosting/scanner/tests/test_email.py (+6/-3)
To merge this branch: bzr merge lp:~frankban/launchpad/bug-1015318
Reviewer Review Type Date Requested Status
Graham Binns (community) code 2012-06-22 Approve on 2012-06-22
Review via email: mp+111577@code.launchpad.net

Commit Message

Fixed lp.codehosting.scanner.tests.test_email.TestViaCelery.test_revisions_added failing intermittently/rarely in parallel tests

Description of the Change

= Summary =

lp.codehosting.scanner.tests.test_email.TestViaCelery.test_revisions_added fails when run right after
lp.registry.tests.test_sharingjob.RemoveBugSubscriptionsJobTestCase.test_getErrorRecipients and
lp.registry.tests.test_sharingjob.RemoveBugSubscriptionsJobTestCase.test_change_target.

The failure is a database disconnection error probably raised because transaction.commit() is called on an old connection.
commit is itself called by a celery job that retrieves notification emails: pop_remote_notifications().

== Proposed fix ==

Enable and start a job in order to recreate a connection before calling pop_remote_notifications().

== Implementation details ==

RevisionMailJob sends emails about revisions when a revision is added to a branch. We execute this job and then flush the notifications, so that we can then test that RevisionsAddedJob is actually called via celery.

== Tests ==

bin/test -cvv --load-list mylist

where mylist contains:

lp.registry.tests.test_sharingjob.RemoveBugSubscriptionsJobTestCase.test_getErrorRecipients
lp.registry.tests.test_sharingjob.RemoveBugSubscriptionsJobTestCase.test_change_target
lp.codehosting.scanner.tests.test_email.TestViaCelery.test_revisions_added

NO QA

To post a comment you must log in.
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/codehosting/scanner/tests/test_email.py'
2--- lib/lp/codehosting/scanner/tests/test_email.py 2012-06-14 05:18:22 +0000
3+++ lib/lp/codehosting/scanner/tests/test_email.py 2012-06-22 12:09:19 +0000
4@@ -200,11 +200,14 @@
5 self.assertEqual(1, len(pop_remote_notifications()))
6
7 def test_revisions_added(self):
8- """RevisionMailJob for removed revisions runs via Celery."""
9- db_branch, tree = self.prepare('RevisionsAddedJob')
10+ """RevisionsAddedJob for added revisions runs via Celery."""
11+ # Enable RevisionMailJob to let celery activate a new connection
12+ # before trying to flush sent emails calling pop_remote_notifications.
13+ db_branch, tree = self.prepare('RevisionMailJob RevisionsAddedJob')
14 tree.commit('message')
15 bzr_sync = BzrSync(db_branch)
16- bzr_sync.syncBranchAndClose(tree.branch)
17+ with block_on_job():
18+ bzr_sync.syncBranchAndClose(tree.branch)
19 pop_remote_notifications()
20 tree.commit('message2')
21 with block_on_job():