~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/buildmaster/tests/test_manager.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:
82
82
        'bob' builder.
83
83
        """
84
84
        super(TestSlaveScannerScan, self).setUp()
85
 
        self.slave = self.useFixture(BuilddSlaveTestSetup())
86
 
 
87
85
        # Creating the required chroots needed for dispatching.
88
86
        test_publisher = make_publisher()
89
87
        ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
212
210
 
213
211
    def testScanRescuesJobFromBrokenBuilder(self):
214
212
        # The job assigned to a broken builder is rescued.
 
213
        self.useFixture(BuilddSlaveTestSetup())
215
214
 
216
215
        # Sampledata builder is enabled and is assigned to an active job.
217
216
        builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
420
419
 
421
420
        return d.addCallback(check)
422
421
 
 
422
    def test_cancelling_a_build(self):
 
423
        # When scanning an in-progress build, if its state is CANCELLING
 
424
        # then the build should be stopped and moved to the CANCELLED state.
 
425
 
 
426
        # Set up a building slave with a fake resume method so we can see
 
427
        # if it got called later.
 
428
        slave = BuildingSlave(build_id="8-1")
 
429
        call_counter = FakeMethod()
 
430
        def fake_resume():
 
431
            call_counter()
 
432
            return defer.succeed((None, None, 0))
 
433
        slave.resume = fake_resume
 
434
 
 
435
        # Set the sample data builder building with the slave from above.
 
436
        builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
 
437
        login('foo.bar@canonical.com')
 
438
        builder.builderok = True
 
439
        # For now, we can only cancel virtual builds.
 
440
        builder.virtualized = True
 
441
        builder.vm_host = "fake_vm_host"
 
442
        builder.setSlaveForTesting(slave)
 
443
        transaction.commit()
 
444
        login(ANONYMOUS)
 
445
        buildqueue = builder.currentjob
 
446
        self.assertBuildingJob(buildqueue, builder)
 
447
 
 
448
        # Now set the build to CANCELLING.
 
449
        build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(buildqueue)
 
450
        build.status = BuildStatus.CANCELLING
 
451
 
 
452
        # Run 'scan' and check its results.
 
453
        self.layer.switchDbUser(config.builddmaster.dbuser)
 
454
        scanner = self._getScanner()
 
455
        d = scanner.scan()
 
456
 
 
457
        def check_cancelled(ignore, builder, buildqueue):
 
458
            self.assertEqual(1, call_counter.call_count)
 
459
            self.assertEqual(BuildStatus.CANCELLED, build.status)
 
460
 
 
461
        d.addCallback(check_cancelled, builder, buildqueue)
 
462
        return d
 
463
 
423
464
 
424
465
class TestBuilddManager(TestCase):
425
466