~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/puller/tests/test_scheduler.py

  • Committer: Robert Collins
  • Date: 2011-10-17 05:41:34 UTC
  • mto: This revision was merged to the branch mainline in revision 14213.
  • Revision ID: robertc@robertcollins.net-20111017054134-m1bo7gi6s6aixc7h
Nuke setOopsToken unneeded in a concurrency safe world.

Show diffs side-by-side

added added

removed removed

Lines of Context:
431
431
        self.arbitrary_branch_id = 1
432
432
        self.eventHandler = scheduler.PullerMaster(
433
433
            self.arbitrary_branch_id, 'arbitrary-source', 'arbitrary-dest',
434
 
            BranchType.HOSTED, None, logging.getLogger(), self.status_client,
435
 
            set(['oops-prefix']))
 
434
            BranchType.HOSTED, None, logging.getLogger(), self.status_client)
436
435
 
437
436
    def test_unexpectedError(self):
438
437
        """The puller master logs an OOPS when it receives an unexpected
503
502
 
504
503
    def setUp(self):
505
504
        super(TestPullerMasterSpawning, self).setUp()
506
 
        self.available_oops_prefixes = set(['foo'])
507
505
        self.eventHandler = self.makePullerMaster(
508
 
            'HOSTED', oops_prefixes=self.available_oops_prefixes)
 
506
            'HOSTED')
509
507
        self.patch(reactor, 'spawnProcess', self.spawnProcess)
510
508
        self.commands_spawned = []
511
509
 
512
 
    def makePullerMaster(self, branch_type_name, default_stacked_on_url=None,
513
 
                         oops_prefixes=None):
 
510
    def makePullerMaster(self, branch_type_name, default_stacked_on_url=None):
514
511
        if default_stacked_on_url is None:
515
512
            default_stacked_on_url = self.factory.getUniqueURL()
516
 
        if oops_prefixes is None:
517
 
            oops_prefixes = set([self.factory.getUniqueString()])
518
513
        return scheduler.PullerMaster(
519
514
            branch_id=self.factory.getUniqueInteger(),
520
515
            source_url=self.factory.getUniqueURL(),
522
517
            branch_type_name=branch_type_name,
523
518
            default_stacked_on_url=default_stacked_on_url,
524
519
            logger=logging.getLogger(),
525
 
            client=FakeCodehostingEndpointProxy(),
526
 
            available_oops_prefixes=oops_prefixes)
527
 
 
528
 
    @property
529
 
    def oops_prefixes(self):
530
 
        """The OOPS prefixes passed to workers on the command line."""
531
 
        # The OOPS prefix is the second-last argument on the command line. We
532
 
        # harvest these from 'commands_spawned', which is a log of the
533
 
        # commands passed to reactor.spawnProcess.
534
 
        return [arguments[-2] for arguments in self.commands_spawned]
 
520
            client=FakeCodehostingEndpointProxy())
535
521
 
536
522
    def spawnProcess(self, protocol, executable, arguments, env):
537
523
        self.commands_spawned.append(arguments)
553
539
        self.assertEqual(
554
540
            [''], [arguments[-1] for arguments in self.commands_spawned])
555
541
 
556
 
    def test_getsOopsPrefixFromSet(self):
557
 
        # Different workers should have different OOPS prefixes. They get
558
 
        # those prefixes from a limited set of possible prefixes.
559
 
        self.eventHandler.run()
560
 
        self.assertEqual(self.available_oops_prefixes, set())
561
 
        self.assertEqual(self.oops_prefixes, ['foo'])
562
 
 
563
 
    def test_restoresOopsPrefixToSetOnSuccess(self):
564
 
        # When a worker finishes running, they restore the OOPS prefix to the
565
 
        # set of available prefixes.
566
 
        deferred = self.eventHandler.run()
567
 
        # Fake a successful run.
568
 
        deferred.callback(None)
569
 
 
570
 
        def check_available_prefixes(ignored):
571
 
            self.assertEqual(self.available_oops_prefixes, set(['foo']))
572
 
 
573
 
        return deferred.addCallback(check_available_prefixes)
574
 
 
575
 
    def test_restoresOopsPrefixToSetOnFailure(self):
576
 
        # When a worker finishes running, they restore the OOPS prefix to the
577
 
        # set of available prefixes, even if the worker failed.
578
 
        deferred = self.eventHandler.run()
579
 
        # Fake a failed run.
580
 
        try:
581
 
            raise RuntimeError("Spurious error")
582
 
        except RuntimeError:
583
 
            fail = failure.Failure()
584
 
        deferred.errback(fail)
585
 
 
586
 
        def check_available_prefixes(ignored):
587
 
            self.assertEqual(self.available_oops_prefixes, set(['foo']))
588
 
 
589
 
        return deferred.addErrback(check_available_prefixes)
590
 
 
591
 
    def test_logOopsWhenNoAvailablePrefix(self):
592
 
        # If there are no available prefixes then we log an OOPS and re-raise
593
 
        # the error, aborting the rest of the run.
594
 
 
595
 
        # Empty the set of available OOPS prefixes
596
 
        self.available_oops_prefixes.clear()
597
 
 
598
 
        unexpected_errors = []
599
 
 
600
 
        def unexpectedError(failure):
601
 
            unexpected_errors.append(failure)
602
 
 
603
 
        self.eventHandler.unexpectedError = unexpectedError
604
 
        self.assertRaises(KeyError, self.eventHandler.run)
605
 
        self.assertEqual(unexpected_errors[0].type, KeyError)
606
 
 
607
542
 
608
543
# The common parts of all the worker scripts.  See
609
544
# TestPullerMasterIntegration.makePullerMaster for more.
614
549
parser = OptionParser()
615
550
(options, arguments) = parser.parse_args()
616
551
(source_url, destination_url, branch_id, unique_name,
617
 
 branch_type_name, oops_prefix, default_stacked_on_url) = arguments
 
552
 branch_type_name, default_stacked_on_url) = arguments
618
553
from bzrlib import branch
619
554
branch = branch.Branch.open(destination_url)
620
555
protocol = PullerWorkerProtocol(sys.stdout)
663
598
        puller_master = cls(
664
599
            self.db_branch.id, str(self.db_branch.url),
665
600
            self.db_branch.unique_name[1:], self.db_branch.branch_type.name,
666
 
            '', logging.getLogger(), self.client,
667
 
            set([config.error_reports.oops_prefix]))
 
601
            '', logging.getLogger(), self.client)
668
602
        puller_master.destination_url = os.path.abspath('dest-branch')
669
603
        if script_text is not None:
670
604
            script = open('script.py', 'w')