Пример #1
0
    def testStopBuildWaitingForStepLocks(self):
        b = self.build

        lock = WorkerLock('lock')
        lock_access = lock.access('counting')
        lock.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(lock) \
            .getLock(self.workerforbuilder.worker)

        step = LoggingBuildStep(locks=[lock_access])
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), lock.access('counting'))

        gotLocks = [False]

        def acquireLocks(res=None):
            gotLocks[0] = True
            retval = LoggingBuildStep.acquireLocks(step, res)
            self.assertTrue(b.currentStep is step)
            b.stopBuild('stop it')
            return retval
        step.acquireLocks = acquireLocks

        b.startBuild(FakeBuildStatus(), self.workerforbuilder)

        self.assertEqual(gotLocks, [True])
        self.assertEqual(b.results, CANCELLED)
Пример #2
0
    def testStopBuildWaitingForLocks(self):
        b = self.build

        lock = WorkerLock('lock')
        lock_access = lock.access('counting')
        lock.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(lock) \
            .getLock(self.workerforbuilder.worker)
        b.setLocks([lock_access])

        step = FakeBuildStep()
        step.alwaysRun = False
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), lock.access('counting'))

        def acquireLocks(res=None):
            retval = Build.acquireLocks(b, res)
            b.stopBuild('stop it')
            return retval
        b.acquireLocks = acquireLocks

        b.startBuild(FakeBuildStatus(), self.workerforbuilder)

        self.assertTrue(b.currentStep is None)
        self.assertEqual(b.results, CANCELLED)
Пример #3
0
    def testStopBuildWaitingForLocks_lostRemote(self):
        b = self.build

        lock = WorkerLock('lock')
        lock_access = lock.access('counting')
        lock.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(lock) \
            .getLock(self.workerforbuilder.worker)
        b.setLocks([lock_access])

        step = FakeBuildStep()
        step.alwaysRun = False
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), lock.access('counting'))

        def acquireLocks(res=None):
            retval = Build.acquireLocks(b, res)
            b.lostRemote()
            return retval
        b.acquireLocks = acquireLocks

        b.startBuild(FakeBuildStatus(), self.workerforbuilder)

        self.assertTrue(b.currentStep is None)
        self.assertEqual(b.results, RETRY)
        self.build.build_status.setText.assert_called_with(
            ["retry", "lost", "connection"])
        self.build.build_status.setResults.assert_called_with(RETRY)
Пример #4
0
    def testBuildWaitingForLocks(self):
        b = self.build

        l = WorkerLock('lock')
        claimCount = [0]
        lock_access = l.access('counting')
        l.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(l) \
            .getLock(self.workerforbuilder.worker)

        def claim(owner, access):
            claimCount[0] += 1
            return real_lock.old_claim(owner, access)
        real_lock.old_claim = real_lock.claim
        real_lock.claim = claim
        b.setLocks([lock_access])

        step = Mock()
        step.return_value = step
        step.startStep.return_value = SUCCESS
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), l.access('counting'))

        b.startBuild(FakeBuildStatus(), None, self.workerforbuilder)

        self.assert_(('startStep', (self.workerforbuilder.worker.conn,), {})
                     not in step.method_calls)
        self.assertEquals(claimCount[0], 1)
        self.assert_(b.currentStep is None)
        self.assert_(b._acquiringLock is not None)
Пример #5
0
    def testBuildWaitingForLocks(self):
        b = self.build

        lock = WorkerLock('lock')
        claimCount = [0]
        lock_access = lock.access('counting')
        lock.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(lock) \
            .getLock(self.workerforbuilder.worker)

        def claim(owner, access):
            claimCount[0] += 1
            return real_lock.old_claim(owner, access)
        real_lock.old_claim = real_lock.claim
        real_lock.claim = claim
        b.setLocks([lock_access])

        step = FakeBuildStep()
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), lock.access('counting'))

        b.startBuild(FakeBuildStatus(), self.workerforbuilder)

        self.assertEqual(claimCount[0], 1)
        self.assertTrue(b.currentStep is None)
        self.assertTrue(b._acquiringLock is not None)
Пример #6
0
    def testStopBuildWaitingForLocks_lostRemote(self):
        b = self.build

        l = WorkerLock('lock')
        lock_access = l.access('counting')
        l.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(l) \
            .getLock(self.workerforbuilder.worker)
        b.setLocks([lock_access])

        step = Mock()
        step.return_value = step
        step.startStep.return_value = SUCCESS
        step.alwaysRun = False
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), l.access('counting'))

        def acquireLocks(res=None):
            retval = Build.acquireLocks(b, res)
            b.lostRemote()
            return retval
        b.acquireLocks = acquireLocks

        b.startBuild(FakeBuildStatus(), None, self.workerforbuilder)

        self.assert_(('startStep', (self.workerforbuilder.worker.conn,), {})
                     not in step.method_calls)
        self.assert_(b.currentStep is None)
        self.assertEqual(b.results, RETRY)
        self.assert_(('interrupt', ('stop it',), {}) not in step.method_calls)
        self.build.build_status.setText.assert_called_with(["retry", "lost", "connection"])
        self.build.build_status.setResults.assert_called_with(RETRY)
Пример #7
0
    def testBuildcanStartWithWorkerForBuilder(self):
        b = self.build

        workerforbuilder1 = Mock()
        workerforbuilder2 = Mock()

        l = WorkerLock('lock')
        counting_access = l.access('counting')
        real_lock = b.builder.botmaster.getLockByID(l)

        # no locks, so both these pass (call twice to verify there's no state/memory)
        lock_list = [(real_lock, counting_access)]
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))

        worker_lock_1 = real_lock.getLock(workerforbuilder1.worker)
        worker_lock_2 = real_lock.getLock(workerforbuilder2.worker)

        # then have workerforbuilder2 claim its lock:
        worker_lock_2.claim(workerforbuilder2, counting_access)
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
        self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
        self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
        worker_lock_2.release(workerforbuilder2, counting_access)

        # then have workerforbuilder1 claim its lock:
        worker_lock_1.claim(workerforbuilder1, counting_access)
        self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
        self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
        self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
        worker_lock_1.release(workerforbuilder1, counting_access)
Пример #8
0
    def testStopBuildWaitingForLocks(self):
        b = self.build

        l = WorkerLock('lock')
        lock_access = l.access('counting')
        l.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(l) \
            .getLock(self.workerforbuilder.worker)
        b.setLocks([lock_access])

        step = Mock()
        step.return_value = step
        step.startStep.return_value = SUCCESS
        step.alwaysRun = False
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), l.access('counting'))

        def acquireLocks(res=None):
            retval = Build.acquireLocks(b, res)
            b.stopBuild('stop it')
            return retval
        b.acquireLocks = acquireLocks

        b.startBuild(FakeBuildStatus(), self.workerforbuilder)

        self.assertNotIn(('startStep', (self.workerforbuilder.worker.conn,), {}),
                         step.method_calls)
        self.assertTrue(b.currentStep is None)
        self.assertEqual(b.results, CANCELLED)
        self.assertNotIn(('interrupt', ('stop it',), {}), step.method_calls)
Пример #9
0
    def testBuildLocksAcquired(self):
        b = self.build

        l = WorkerLock('lock')
        claimCount = [0]
        lock_access = l.access('counting')
        l.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(l) \
            .getLock(self.workerforbuilder.worker)

        def claim(owner, access):
            claimCount[0] += 1
            return real_lock.old_claim(owner, access)
        real_lock.old_claim = real_lock.claim
        real_lock.claim = claim
        b.setLocks([lock_access])

        step = Mock()
        step.return_value = step
        step.startStep.return_value = SUCCESS
        b.setStepFactories([FakeStepFactory(step)])

        b.startBuild(FakeBuildStatus(), self.workerforbuilder)

        self.assertEqual(b.results, SUCCESS)
        self.assertIn(('startStep', (self.workerforbuilder.worker.conn,), {}),
                      step.method_calls)
        self.assertEquals(claimCount[0], 1)
Пример #10
0
    def testStopBuildWaitingForLocks(self):
        b = self.build

        l = WorkerLock("lock")
        lock_access = l.access("counting")
        l.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(l).getLock(self.workerbuilder.worker)
        b.setLocks([lock_access])

        step = Mock()
        step.return_value = step
        step.startStep.return_value = SUCCESS
        step.alwaysRun = False
        b.setStepFactories([FakeStepFactory(step)])

        real_lock.claim(Mock(), l.access("counting"))

        def acquireLocks(res=None):
            retval = Build.acquireLocks(b, res)
            b.stopBuild("stop it")
            return retval

        b.acquireLocks = acquireLocks

        b.startBuild(FakeBuildStatus(), None, self.workerbuilder)

        self.assert_(("startStep", (self.workerbuilder.worker.conn,), {}) not in step.method_calls)
        self.assert_(b.currentStep is None)
        self.assertEqual(b.results, CANCELLED)
        self.assert_(("interrupt", ("stop it",), {}) not in step.method_calls)
Пример #11
0
    def testBuildLocksOrder(self):
        """Test that locks are acquired in FIFO order; specifically that
        counting locks cannot jump ahead of exclusive locks"""
        eBuild = self.build

        cBuilder = FakeBuilder(self.master)
        cBuild = Build([self.request])
        cBuild.setBuilder(cBuilder)

        eWorker = Mock()
        cWorker = Mock()

        eWorker.worker = self.worker
        cWorker.worker = self.worker
        eWorker.prepare = cWorker.prepare = lambda _: True
        eWorker.ping = cWorker.ping = lambda: True

        l = WorkerLock("lock", 2)
        claimLog = []
        realLock = self.master.botmaster.getLockByID(l).getLock(self.worker)

        def claim(owner, access):
            claimLog.append(owner)
            return realLock.oldClaim(owner, access)

        realLock.oldClaim = realLock.claim
        realLock.claim = claim

        eBuild.setLocks([l.access("exclusive")])
        cBuild.setLocks([l.access("counting")])

        fakeBuild = Mock()
        fakeBuildAccess = l.access("counting")
        realLock.claim(fakeBuild, fakeBuildAccess)

        step = Mock()
        step.return_value = step
        step.startStep.return_value = SUCCESS
        eBuild.setStepFactories([FakeStepFactory(step)])
        cBuild.setStepFactories([FakeStepFactory(step)])

        e = eBuild.startBuild(FakeBuildStatus(), eWorker)
        c = cBuild.startBuild(FakeBuildStatus(), cWorker)
        d = defer.DeferredList([e, c])

        realLock.release(fakeBuild, fakeBuildAccess)

        def check(ign):
            self.assertEqual(eBuild.results, SUCCESS)
            self.assertEqual(cBuild.results, SUCCESS)
            self.assertEqual(claimLog, [fakeBuild, eBuild, cBuild])

        d.addCallback(check)
        return d
Пример #12
0
    def testBuildLocksAcquired(self):
        b = self.build

        lock = WorkerLock('lock')
        claimCount = [0]
        lock_access = lock.access('counting')
        lock.access = lambda mode: lock_access
        real_lock = b.builder.botmaster.getLockByID(lock) \
            .getLock(self.workerforbuilder.worker)

        def claim(owner, access):
            claimCount[0] += 1
            return real_lock.old_claim(owner, access)
        real_lock.old_claim = real_lock.claim
        real_lock.claim = claim
        b.setLocks([lock_access])

        step = FakeBuildStep()
        b.setStepFactories([FakeStepFactory(step)])

        b.startBuild(FakeBuildStatus(), self.workerforbuilder)

        self.assertEqual(b.results, SUCCESS)
        self.assertEqual(claimCount[0], 1)