Merge lp:~cjwatson/launchpad/simplify-packagecopyjob-tests into lp:launchpad

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: no longer in the source branch.
Merged at revision: 15643
Proposed branch: lp:~cjwatson/launchpad/simplify-packagecopyjob-tests
Merge into: lp:launchpad
Diff against target: 135 lines (+18/-36)
1 file modified
lib/lp/soyuz/tests/test_packagecopyjob.py (+18/-36)
To merge this branch: bzr merge lp:~cjwatson/launchpad/simplify-packagecopyjob-tests
Reviewer Review Type Date Requested Status
Richard Harding (community) Approve
Review via email: mp+115159@code.launchpad.net

Commit message

Use the job runner directly rather than mimicking it.

Description of the change

There is no point in mimicking the job runner in the PCJ tests; it isn't any faster as far as I can tell, and it introduces an extra source of possible mistakes. We might as well just use the job runner directly.

To post a comment you must log in.
Revision history for this message
Richard Harding (rharding) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
2--- lib/lp/soyuz/tests/test_packagecopyjob.py 2012-07-12 08:52:45 +0000
3+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2012-07-16 14:35:33 +0000
4@@ -6,7 +6,6 @@
5 import operator
6 from textwrap import dedent
7
8-from lazr.jobrunner.jobrunner import SuspendJobException
9 from storm.store import Store
10 from testtools.content import text_content
11 from testtools.matchers import MatchesStructure
12@@ -25,6 +24,7 @@
13 from lp.services.database.lpstorm import IStore
14 from lp.services.features.testing import FeatureFixture
15 from lp.services.job.interfaces.job import JobStatus
16+from lp.services.job.runner import JobRunner
17 from lp.services.job.tests import (
18 block_on_job,
19 pop_remote_notifications,
20@@ -163,22 +163,8 @@
21
22 def runJob(self, job):
23 """Helper to switch to the right DB user and run the job."""
24- # We are basically mimicking the job runner here.
25 switch_dbuser(self.dbuser)
26- # Set the state to RUNNING.
27- job.start()
28- # Commit the RUNNING state.
29- self.layer.txn.commit()
30- try:
31- job.run()
32- except SuspendJobException:
33- # Re-raise this one as many tests check for its presence.
34- raise
35- except:
36- transaction.abort()
37- job.fail()
38- else:
39- job.complete()
40+ JobRunner([job]).runAll()
41
42
43 class PlainPackageCopyJobTests(TestCaseWithFactory, LocalTestHelper):
44@@ -755,10 +741,8 @@
45 include_binaries=False,
46 requester=requester)
47
48- self.assertRaises(SuspendJobException, self.runJob, job)
49- # Simulate the job runner suspending after getting a
50- # SuspendJobException
51- job.suspend()
52+ self.runJob(job)
53+ self.assertEqual(JobStatus.SUSPENDED, job.status)
54 switch_dbuser("launchpad_main")
55
56 # Add some overrides to the job.
57@@ -816,7 +800,8 @@
58
59 # The job should be suspended and there's a PackageUpload with
60 # its package_copy_job set.
61- self.assertRaises(SuspendJobException, self.runJob, job)
62+ self.runJob(job)
63+ self.assertEqual(JobStatus.SUSPENDED, job.status)
64 pu = Store.of(target_archive).find(
65 PackageUpload,
66 PackageUpload.package_copy_job_id == job.id).one()
67@@ -864,8 +849,8 @@
68 job = self.createCopyJobForSPPH(spph, source_archive, target_archive)
69
70 # Run the job so it gains a PackageUpload.
71- self.assertRaises(SuspendJobException, self.runJob, job)
72- job.suspend()
73+ self.runJob(job)
74+ self.assertEqual(JobStatus.SUSPENDED, job.status)
75 if return_job:
76 return job
77 pcj = removeSecurityProxy(job).context
78@@ -926,7 +911,8 @@
79
80 # The job should be suspended and there's a PackageUpload with
81 # its package_copy_job set in the UNAPPROVED queue.
82- self.assertRaises(SuspendJobException, self.runJob, job)
83+ self.runJob(job)
84+ self.assertEqual(JobStatus.SUSPENDED, job.status)
85
86 pu = Store.of(target_archive).find(
87 PackageUpload,
88@@ -963,10 +949,8 @@
89 spph, source_archive, target_archive, requester=requester)
90
91 # Run the job so it gains a PackageUpload.
92- self.assertRaises(SuspendJobException, self.runJob, job)
93- # Simulate the job runner suspending after getting a
94- # SuspendJobException
95- job.suspend()
96+ self.runJob(job)
97+ self.assertEqual(JobStatus.SUSPENDED, job.status)
98 switch_dbuser("launchpad_main")
99
100 # Accept the upload to release the job then run it.
101@@ -1099,8 +1083,8 @@
102 self.assertTrue(job.unembargo)
103
104 # Run the job so it gains a PackageUpload.
105- self.assertRaises(SuspendJobException, self.runJob, job)
106- job.suspend()
107+ self.runJob(job)
108+ self.assertEqual(JobStatus.SUSPENDED, job.status)
109 switch_dbuser("launchpad_main")
110
111 # Accept the upload to release the job then run it.
112@@ -1152,8 +1136,8 @@
113 include_binaries=True)
114
115 # Start, accept, and run the job.
116- self.assertRaises(SuspendJobException, self.runJob, job)
117- job.suspend()
118+ self.runJob(job)
119+ self.assertEqual(JobStatus.SUSPENDED, job.status)
120 switch_dbuser("launchpad_main")
121 pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
122 [removeSecurityProxy(job).context.id]).one()
123@@ -1320,10 +1304,8 @@
124 source_pub, source_archive, target_archive)
125
126 # Run the job so it gains a PackageUpload.
127- self.assertRaises(SuspendJobException, self.runJob, job)
128- # Simulate the job runner suspending after getting a
129- # SuspendJobException
130- job.suspend()
131+ self.runJob(job)
132+ self.assertEqual(JobStatus.SUSPENDED, job.status)
133 switch_dbuser("launchpad_main")
134
135 # Patch the job's attemptCopy() method so it just raises an