Merge lp:~abentley/launchpad/same-queue-query-fmr into lp:launchpad

Proposed by Aaron Bentley on 2012-08-06
Status: Merged
Approved by: Aaron Bentley on 2012-08-07
Approved revision: no longer in the source branch.
Merged at revision: 15760
Proposed branch: lp:~abentley/launchpad/same-queue-query-fmr
Merge into: lp:launchpad
Diff against target: 65 lines (+21/-12)
1 file modified
lib/lp/services/job/tests/test_celeryjob.py (+21/-12)
To merge this branch: bzr merge lp:~abentley/launchpad/same-queue-query-fmr
Reviewer Review Type Date Requested Status
Abel Deuring (community) code 2012-08-06 Approve on 2012-08-07
Review via email: mp+118428@code.launchpad.net

Commit Message

Directly use matching queue in test_find_missing_ready

Description of the Change

= Summary =
test_find_misssing_ready seems to fail because the contents of the queue vary between queries.

== Proposed fix ==
When the queue has been determined to be in the correct state, use that query directly instead of re-querying the queue.

== Pre-implementation notes ==
Discussed with deryck

== LOC Rationale ==
I have a LOC credit of 1860

== Implementation details ==
Implement getFMR, as a variant of assertQueueSize that uses FindMissingReady to query the queue, and returns the instance that had a successful query.

== Tests ==
bin/test -t test_find_missing_ready

== Demo and Q/A ==
None

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/services/job/tests/test_celeryjob.py

To post a comment you must log in.
Abel Deuring (adeuring) wrote :

I see how this is an improvement: only one call of list_queued(), so r=me. But the fact that list_queued() can obviously return different data in two calls when the message server should not have received of delivered any message, at least for Celery related queues, still scares me...

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/services/job/tests/test_celeryjob.py'
2--- lib/lp/services/job/tests/test_celeryjob.py 2012-08-02 15:44:50 +0000
3+++ lib/lp/services/job/tests/test_celeryjob.py 2012-08-06 20:58:22 +0000
4@@ -42,6 +42,20 @@
5 self.addCleanup(drain_celery_queues)
6 return job
7
8+ def getFMR(self, job_source, expected_len):
9+ """Get a FindMissingReady object when job queue reaches expected size.
10+
11+ Fails if the queue never reaches the expected size.
12+ """
13+ from lp.services.job.celeryjob import FindMissingReady
14+ for x in range(600):
15+ find_missing = FindMissingReady(job_source)
16+ if len(find_missing.queue_contents) == expected_len:
17+ return find_missing
18+ sleep(0.1)
19+ self.fail('Queue size did not reach %d; still at %d' %
20+ (expected_len, len(find_missing.queue_contents)))
21+
22 def assertQueueSize(self, app, queues, expected_len):
23 """Assert the message queue (eventually) reaches the specified size.
24
25@@ -63,23 +77,19 @@
26
27 def test_find_missing_ready(self):
28 """A job which is ready but not queued is "missing"."""
29- from lp.services.job.celeryjob import FindMissingReady
30 job = self.createMissingJob()
31 self.addTextDetail(
32 'job_info', 'job.id: %d, job.job_id: %d' % (job.id, job.job_id))
33- self.assertQueueSize(self.CeleryRunJob.app,
34- [BranchScanJob.task_queue], 0)
35- self.assertEqual([job], self.find_missing_ready(BranchScanJob))
36+ find_missing_ready_obj = self.getFMR(BranchScanJob, 0)
37+ self.assertEqual([job], find_missing_ready_obj.find_missing_ready())
38 job.runViaCelery()
39- self.assertQueueSize(self.CeleryRunJob.app,
40- [BranchScanJob.task_queue], 1)
41- # XXX AaronBentley: 2012-08-01 bug=1031018: Extra diagnostic info to
42- # help diagnose this hard-to-reproduce failure.
43- find_missing_ready_obj = FindMissingReady(BranchScanJob)
44+ find_missing_ready_obj = self.getFMR(BranchScanJob, 1)
45 missing_ready = find_missing_ready_obj.find_missing_ready()
46 try:
47 self.assertEqual([], missing_ready)
48 except:
49+ # XXX AaronBentley: 2012-08-01 bug=1031018: Extra diagnostic info
50+ # to help diagnose this hard-to-reproduce failure.
51 self.addTextDetail('queued_job_ids',
52 '%r' % (find_missing_ready_obj.queued_job_ids))
53 self.addTextDetail('queue_contents',
54@@ -89,9 +99,8 @@
55 missing_ready]))
56 raise
57 drain_celery_queues()
58- self.assertQueueSize(self.CeleryRunJob.app,
59- [BranchScanJob.task_queue], 0)
60- self.assertEqual([job], self.find_missing_ready(BranchScanJob))
61+ find_missing_ready_obj = self.getFMR(BranchScanJob, 0)
62+ self.assertEqual([job], find_missing_ready_obj.find_missing_ready())
63
64 def test_run_missing_ready_not_enabled(self):
65 """run_missing_ready does nothing if the class isn't enabled."""