예제 #1
0
    def testFinishWork(self):
        """ 
        testFinishWork makes assertations about things
        that should happen when a HelperRobot is asked
        to finish a task.
        """
        mediator = RobotMediator()
        helper = HelperRobot(mediator)
        master = MasterRobot(mediator)

        # Try telling master to finish job without
        # assigning any work.
        with self.assertRaises(NotBusyException):
            master.finishWork()
            master.finishWork()
        
        # But if it's working on a task, it should
        # gracefully finish the task.
        try:
            master.doWork()
            master.finishWork()
        except Exception as e:
            self.fail(e)  
예제 #2
0
    def testDoWorkA(self):
        """
        testDoWork makes assertations about things
        that should happen when a MasterRobot is asked
        to perform a task.
        """
        # -------------------------- #
        # 1 master and 1 helper      #
        # -------------------------- #
        mediator = RobotMediator()
        helper = HelperRobot(mediator)
        master = MasterRobot(mediator)
    
        # Assign one job.
        try:
            master.doWork()
        except TooBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 1 running 0 queued.
        self.assertEquals(1, master.getRunningJobs())
        self.assertEquals(0, master.getQueuedJobs())
        
        # Assign second job.
        try:
            master.doWork()
        except TooBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 2 running 0 queued.
        self.assertEquals(2, master.getRunningJobs())
        self.assertEquals(0, master.getQueuedJobs())

        # Assign third job.
        try:
            master.doWork()
        except TooBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 2 running 1 queued.
        self.assertEquals(2, master.getRunningJobs())
        self.assertEquals(1, master.getQueuedJobs())

        # Assign fourth job.
        try:
            master.doWork()
        except TooBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 2 running 2 queued.
        self.assertEquals(2, master.getRunningJobs())
        self.assertEquals(2, master.getQueuedJobs())
        
        # Tell the helper that it's finished doing
        # its job.
        try:
            helper.finishWork()
        except NotBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 2 running 1 queued.
        self.assertEquals(2, master.getRunningJobs())
        self.assertEquals(1, master.getQueuedJobs())
        
        # Tell the helper that it's finished doing
        # its job.
        try:
            helper.finishWork()
        except NotBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 2 running 0 queued.
        self.assertEquals(2, master.getRunningJobs())
        self.assertEquals(0, master.getQueuedJobs())
        

        # Tell the helper that it's finished doing
        # its job.
        try:
            helper.finishWork()
        except NotBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 1 running 0 queued.
        self.assertEquals(1, master.getRunningJobs())
        self.assertEquals(0, master.getQueuedJobs())
        
        # Tell the helper that it's finished doing
        # its job.
        try:
            master.finishWork()
        except NotBusyException as e:
            self.fail(e)
        # Verify the status.
        # Should be 0 running 0 queued.
        self.assertEquals(0, master.getRunningJobs())
        self.assertEquals(0, master.getQueuedJobs())