~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-25 16:06:39 UTC
  • mfrom: (14169.3.12 cancel-build-bug-173018)
  • Revision ID: launchpad@pqm.canonical.com-20111025160639-vaijpn40qjfodorn
[r=jtv][bug=173018][incr] First branch in a pipeline of changes to
        add build cancellation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
    datetime,
9
9
    timedelta,
10
10
    )
 
11
from storm.store import Store
 
12
from storm.sqlobject import SQLObjectNotFound
11
13
 
12
14
from pytz import utc
13
15
from zope import component
543
545
        self.assertEqual(1, free_count)
544
546
 
545
547
 
 
548
class TestBuildCancellation(TestCaseWithFactory):
 
549
    """Test cases for cancelling builds."""
 
550
 
 
551
    layer = ZopelessDatabaseLayer
 
552
 
 
553
    def setUp(self):
 
554
        super(TestBuildCancellation, self).setUp()
 
555
        self.builder = self.factory.makeBuilder()
 
556
 
 
557
    def _makeBuildQueue(self, job):
 
558
        return BuildQueue(
 
559
            job=job, lastscore=9999,
 
560
            job_type=BuildFarmJobType.PACKAGEBUILD,
 
561
            estimated_duration=timedelta(seconds=69), virtualized=True)
 
562
 
 
563
    def assertCancelled(self, build, buildqueue):
 
564
        self.assertEqual(BuildStatus.CANCELLED, build.status)
 
565
        self.assertIs(None, buildqueue.specific_job)
 
566
        self.assertRaises(SQLObjectNotFound, BuildQueue.get, buildqueue.id)
 
567
 
 
568
    def test_binarypackagebuild_cancel(self):
 
569
        build = self.factory.makeBinaryPackageBuild()
 
570
        buildpackagejob = build.makeJob()
 
571
        bq = self._makeBuildQueue(buildpackagejob.job)
 
572
        Store.of(build).add(bq)
 
573
        bq.markAsBuilding(self.builder)
 
574
        bq.cancel()
 
575
 
 
576
        self.assertCancelled(buildpackagejob.build, bq)
 
577
 
 
578
    def test_recipebuild_cancel(self):
 
579
        bq = self.factory.makeSourcePackageRecipeBuildJob()
 
580
        build = bq.specific_job.build
 
581
        bq.markAsBuilding(self.builder)
 
582
        bq.cancel()
 
583
 
 
584
        self.assertCancelled(build, bq)
 
585
 
 
586
 
546
587
class TestMinTimeToNextBuilder(SingleArchBuildsBase):
547
588
    """Test estimated time-to-builder with builds targetting a single
548
589
    processor."""