~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/buildmaster/tests/test_builder.py

[r=allenap][bug=905853, 905855,
        906079] Revert r14499 and r14459 because read-only transactions in
        buildmaster are causing production issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Test Builder features."""
8
8
import tempfile
9
9
import xmlrpclib
10
10
 
11
 
from lpbuildd.slave import BuilderStatus
12
11
from testtools.deferredruntest import (
13
12
    assert_fails_with,
14
13
    AsynchronousDeferredRunTest,
15
14
    AsynchronousDeferredRunTestForBrokenTwisted,
16
15
    SynchronousDeferredRunTest,
17
16
    )
18
 
import transaction
 
17
 
19
18
from twisted.internet.defer import (
20
19
    CancelledError,
21
20
    DeferredList,
23
22
from twisted.internet.task import Clock
24
23
from twisted.python.failure import Failure
25
24
from twisted.web.client import getPage
 
25
 
26
26
from zope.component import getUtility
27
27
from zope.security.proxy import (
28
28
    isinstance as zope_isinstance,
29
29
    removeSecurityProxy,
30
30
    )
31
31
 
 
32
from lpbuildd.slave import BuilderStatus
 
33
 
32
34
from canonical.config import config
33
35
from canonical.database.sqlbase import flush_database_updates
34
36
from canonical.launchpad.webapp.interfaces import (
43
45
from lp.buildmaster.enums import BuildStatus
44
46
from lp.buildmaster.interfaces.builder import (
45
47
    CannotFetchFile,
46
 
    CannotResumeHost,
47
48
    IBuilder,
48
49
    IBuilderSet,
49
50
    )
51
52
    IBuildFarmJobBehavior,
52
53
    )
53
54
from lp.buildmaster.interfaces.buildqueue import IBuildQueueSet
 
55
from lp.buildmaster.interfaces.builder import CannotResumeHost
54
56
from lp.buildmaster.model.builder import (
55
57
    BuilderSlave,
56
58
    ProxyWithConnectionTimeout,
72
74
    TrivialBehavior,
73
75
    WaitingSlave,
74
76
    )
75
 
from lp.registry.interfaces.pocket import PackagePublishingPocket
76
 
from lp.services.database.transaction_policy import DatabaseTransactionPolicy
77
77
from lp.services.job.interfaces.job import JobStatus
78
78
from lp.services.log.logger import BufferLogger
79
79
from lp.soyuz.enums import (
155
155
        d = lostbuilding_builder.updateStatus(BufferLogger())
156
156
        def check_slave_status(failure):
157
157
            self.assertIn('abort', slave.call_log)
158
 
            # 'Fault' comes from the LostBuildingBrokenSlave.  This is
 
158
            # 'Fault' comes from the LostBuildingBrokenSlave, this is
159
159
            # just testing that the value is passed through.
160
160
            self.assertIsInstance(failure.value, xmlrpclib.Fault)
161
161
        return d.addBoth(check_slave_status)
534
534
        # And the old_candidate is superseded:
535
535
        self.assertEqual(BuildStatus.SUPERSEDED, build.status)
536
536
 
537
 
    def test_findBuildCandidate_postprocesses_in_read_write_policy(self):
538
 
        # _findBuildCandidate invokes BuildFarmJob.postprocessCandidate,
539
 
        # which may modify the database.  This happens in a read-write
540
 
        # transaction even if _findBuildCandidate itself runs in a
541
 
        # read-only transaction policy.
542
 
 
543
 
        # PackageBuildJob.postprocessCandidate will attempt to delete
544
 
        # security builds.
545
 
        pub = self.publisher.getPubSource(
546
 
            sourcename="gedit", status=PackagePublishingStatus.PUBLISHED,
547
 
            archive=self.factory.makeArchive(),
548
 
            pocket=PackagePublishingPocket.SECURITY)
549
 
        pub.createMissingBuilds()
550
 
        transaction.commit()
551
 
        with DatabaseTransactionPolicy(read_only=True):
552
 
            removeSecurityProxy(self.frog_builder)._findBuildCandidate()
553
 
            # The test is that this passes without a "transaction is
554
 
            # read-only" error.
555
 
            transaction.commit()
556
 
 
557
537
    def test_acquireBuildCandidate_marks_building(self):
558
538
        # acquireBuildCandidate() should call _findBuildCandidate and
559
539
        # mark the build as building.