def testStopBuildWaitingForLocks(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) b.builder.botmaster = FakeMaster() slavebuilder = Mock() status = Mock() l = SlaveLock('lock') lock_access = l.access('counting') l.access = lambda mode: lock_access real_lock = b.builder.botmaster.getLockByID(l).getLock(slavebuilder) b.setLocks([l]) step = Mock() step.return_value = step step.startStep.return_value = SUCCESS b.setStepFactories([(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(status, None, slavebuilder) self.assert_( ('startStep', (b.remote,), {}) not in step.method_calls) self.assert_(b.currentStep is None) self.assertEqual(b.result, EXCEPTION) self.assert_( ('interrupt', ('stop it',), {}) not in step.method_calls)
def testBuildLocksAcquired(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) b.builder.botmaster = FakeMaster() slavebuilder = Mock() status = Mock() l = SlaveLock('lock') claimCount = [0] lock_access = l.access('counting') l.access = lambda mode: lock_access real_lock = b.builder.botmaster.getLockByID(l).getLock(slavebuilder) 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([l]) step = Mock() step.return_value = step step.startStep.return_value = SUCCESS b.setStepFactories([(step, {})]) b.startBuild(status, None, slavebuilder) self.assertEqual(b.result, SUCCESS) self.assert_(('startStep', (b.remote, ), {}) in step.method_calls) self.assertEquals(claimCount[0], 1)
def testStepDoneWarnings(self): r = FakeRequest() b = Build([r]) b.results = [SUCCESS] b.result = SUCCESS b.remote = Mock() step = FakeBuildStep() terminate = b.stepDone(WARNINGS, step) self.assertEqual(terminate, False) self.assertEqual(b.result, WARNINGS)
def testStepDoneFail(self): r = FakeRequest() b = Build([r]) b.results = [SUCCESS] b.result = SUCCESS b.remote = Mock() step = FakeBuildStep() terminate = b.stepDone(FAILURE, step) self.assertEqual(terminate, False) self.assertEqual(b.result, FAILURE)
def testStepDoneFailOverridesWarnings(self): r = FakeRequest() b = Build([r]) b.results = [SUCCESS, WARNINGS] b.result = WARNINGS b.remote = Mock() step = FakeBuildStep() terminate = b.stepDone(FAILURE, step) self.assertEqual(terminate, False) self.assertEqual(b.result, FAILURE)
def testStepDoneWarningsDontOverrideFailure(self): r = FakeRequest() b = Build([r]) b.results = [FAILURE] b.result = FAILURE b.remote = Mock() step = FakeBuildStep() terminate = b.stepDone(WARNINGS, step) self.assertEqual(terminate, False) self.assertEqual(b.result, FAILURE)
def testBuildLocksAcquired(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) b.builder.botmaster = FakeMaster() slavebuilder = Mock() status = Mock() l = SlaveLock('lock') claimCount = [0] lock_access = l.access('counting') l.access = lambda mode: lock_access real_lock = b.builder.botmaster.getLockByID(l).getLock(slavebuilder) 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([l]) step = Mock() step.return_value = step step.startStep.return_value = SUCCESS b.setStepFactories([(step, {})]) b.startBuild(status, None, slavebuilder) self.assertEqual(b.result, SUCCESS) self.assert_( ('startStep', (b.remote,), {}) in step.method_calls) self.assertEquals(claimCount[0], 1)
def testStepDoneHaltOnFailure(self): r = FakeRequest() b = Build([r]) b.results = [] b.result = SUCCESS b.remote = Mock() step = FakeBuildStep() step.haltOnFailure = True terminate = b.stepDone(FAILURE, step) self.assertEqual(terminate, True) self.assertEqual(b.result, FAILURE)
def testStepDoneWarnOnFailure(self): r = FakeRequest() b = Build([r]) b.results = [SUCCESS] b.result = SUCCESS b.remote = Mock() step = FakeBuildStep() step.warnOnFailure = True step.flunkOnFailure = False terminate = b.stepDone(FAILURE, step) self.assertEqual(terminate, False) self.assertEqual(b.result, WARNINGS)
def testStepDoneHaltOnFailureFlunkOnWarnings(self): r = FakeRequest() b = Build([r]) b.results = [SUCCESS] b.result = SUCCESS b.remote = Mock() step = FakeBuildStep() step.flunkOnWarnings = True self.haltOnFailure = True terminate = b.stepDone(WARNINGS, step) self.assertEqual(terminate, False) self.assertEqual(b.result, FAILURE)
def testStopBuild(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) step = Mock() step.return_value = step b.setStepFactories([(step, {})]) slavebuilder = Mock() status = Mock() def startStep(*args, **kw): # Now interrupt the build b.stopBuild("stop it") return defer.Deferred() step.startStep = startStep b.startBuild(status, None, slavebuilder) self.assertEqual(b.result, EXCEPTION) self.assert_(('interrupt', ('stop it', ), {}) in step.method_calls)
def testStepDoneRetryOverridesAnythingElse(self): r = FakeRequest() b = Build([r]) b.results = [RETRY] b.result = RETRY b.remote = Mock() step = FakeBuildStep() step.alwaysRun = True b.stepDone(WARNINGS, step) b.stepDone(FAILURE, step) b.stepDone(SUCCESS, step) terminate = b.stepDone(EXCEPTION, step) self.assertEqual(terminate, True) self.assertEqual(b.result, RETRY)
def makeBuildStep(basedir, step_class=BuildStep, **kwargs): bss = setupBuildStepStatus(basedir) ss = SourceStamp() setup = {'name': "builder1", "slavename": "bot1", 'builddir': "builddir", 'factory': None} b0 = Builder(setup, bss.getBuild().getBuilder()) br = BuildRequest("reason", ss) b = Build([br]) b.setBuilder(b0) s = step_class(**kwargs) s.setBuild(b) s.setStepStatus(bss) b.setupStatus(bss.getBuild()) s.slaveVersion = fake_slaveVersion return s
def testStopBuild(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) step = Mock() step.return_value = step b.setStepFactories([(step, {})]) slavebuilder = Mock() status = Mock() def startStep(*args, **kw): # Now interrupt the build b.stopBuild("stop it") return defer.Deferred() step.startStep = startStep b.startBuild(status, None, slavebuilder) self.assert_("Interrupted" in b.text) self.assertEqual(b.result, FAILURE) self.assert_( ('interrupt', ('stop it',), {}) in step.method_calls)
def testStepDoneFlunkOnWarningsFlunkOnFailure(self): r = FakeRequest() b = Build([r]) b.results = [] b.result = SUCCESS b.remote = Mock() step = FakeBuildStep() step.flunkOnFailure = True step.flunkOnWarnings = True b.stepDone(WARNINGS, step) terminate = b.stepDone(FAILURE, step) self.assertEqual(terminate, False) self.assertEqual(b.result, FAILURE)
def testRunSuccessfulBuild(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) step = Mock() step.return_value = step step.startStep.return_value = SUCCESS b.setStepFactories([(step, {})]) slavebuilder = Mock() status = Mock() b.startBuild(status, None, slavebuilder) self.assertEqual(b.result, SUCCESS) self.assert_(('startStep', (b.remote, ), {}) in step.method_calls)
def testStopBuildWaitingForStepLocks(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) b.builder.botmaster = FakeMaster() slavebuilder = Mock() status = Mock() l = SlaveLock('lock') lock_access = l.access('counting') l.access = lambda mode: lock_access real_lock = b.builder.botmaster.getLockByID(l).getLock(slavebuilder) step = LoggingBuildStep(locks=[lock_access]) def factory(*args): return step b.setStepFactories([(factory, {})]) real_lock.claim(Mock(), l.access('counting')) gotLocks = [False] def acquireLocks(res=None): gotLocks[0] = True retval = LoggingBuildStep.acquireLocks(step, res) self.assert_(b.currentStep is step) b.stopBuild('stop it') return retval step.acquireLocks = acquireLocks step.setStepStatus = Mock() step.step_status = Mock() step.step_status.addLog().chunkSize = 10 step.step_status.getLogs.return_value = [] b.startBuild(status, None, slavebuilder) self.assertEqual(gotLocks, [True]) self.assert_(('stepStarted', (), {}) in step.step_status.method_calls) self.assertEqual(b.result, EXCEPTION)
def testRunSuccessfulBuild(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) step = Mock() step.return_value = step step.startStep.return_value = SUCCESS b.setStepFactories([(step, {})]) slavebuilder = Mock() status = Mock() b.startBuild(status, None, slavebuilder) self.assertEqual(b.result, SUCCESS) self.assert_( ('startStep', (b.remote,), {}) in step.method_calls)
def testStopBuildWaitingForStepLocks(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) b.builder.botmaster = FakeMaster() slavebuilder = Mock() status = Mock() l = SlaveLock('lock') claimCount = [0] lock_access = l.access('counting') l.access = lambda mode: lock_access real_lock = b.builder.botmaster.getLockByID(l).getLock(slavebuilder) step = LoggingBuildStep(locks=[lock_access]) def factory(*args): return step b.setStepFactories([(factory, {})]) real_lock.claim(Mock(), l.access('counting')) gotLocks = [False] def acquireLocks(res=None): gotLocks[0] = True retval = LoggingBuildStep.acquireLocks(step, res) self.assert_(b.currentStep is step) b.stopBuild('stop it') return retval step.acquireLocks = acquireLocks step.setStepStatus = Mock() step.step_status = Mock() step.step_status.addLog().chunkSize = 10 step.step_status.getLogs.return_value = [] b.startBuild(status, None, slavebuilder) self.assertEqual(gotLocks, [True]) self.assert_(('stepStarted', (), {}) in step.step_status.method_calls) self.assert_("Interrupted" in b.text, b.text) self.assertEqual(b.result, FAILURE)
def makeBuildStep(basedir, step_class=BuildStep, **kwargs): bss = setupBuildStepStatus(basedir) ss = SourceStamp() setup = {"name": "builder1", "slavename": "bot1", "builddir": "builddir", "factory": None} b0 = Builder(setup, bss.getBuild().getBuilder()) b0.botmaster = FakeBotMaster() br = BuildRequest("reason", ss, "test_builder") b = Build([br]) b.setBuilder(b0) s = step_class(**kwargs) s.setBuild(b) s.setStepStatus(bss) b.build_status = bss.getBuild() b.setupProperties() s.slaveVersion = fake_slaveVersion return s
def makeBuildStep(basedir, step_class=BuildStep, **kwargs): bss = setupBuildStepStatus(basedir) ss = SourceStamp() setup = { 'name': "builder1", "slavename": "bot1", 'builddir': "builddir", 'factory': None } b0 = Builder(setup, bss.getBuild().getBuilder()) b0.botmaster = FakeBotMaster() br = BuildRequest("reason", ss) b = Build([br]) b.setBuilder(b0) s = step_class(**kwargs) s.setBuild(b) s.setStepStatus(bss) b.build_status = bss.getBuild() b.setupProperties() s.slaveVersion = fake_slaveVersion return s
def makeBuildStep(basedir, step_class=BuildStep, **kwargs): bss = setupBuildStepStatus(basedir) ss = SourceStamp() setup = {'name': "builder1", "slavename": "bot1", 'builddir': "builddir", 'slavebuilddir': "slavebuilddir", 'factory': None} b0 = Builder(setup, bss.getBuild().getBuilder()) b0.botmaster = FakeBotMaster() br = BuildRequest("reason", ss, 'test_builder') b = Build([br]) b.setBuilder(b0) s = step_class(**kwargs) s.setBuild(b) s.setStepStatus(bss) b.build_status = bss.getBuild() b.setupProperties() s.slaveVersion = fake_slaveVersion s.step_status.setText(s.describe(False)) return s
def testStopBuildWaitingForLocks(self): r = FakeRequest() b = Build([r]) b.setBuilder(Mock()) b.builder.botmaster = FakeMaster() slavebuilder = Mock() status = Mock() l = SlaveLock('lock') lock_access = l.access('counting') l.access = lambda mode: lock_access real_lock = b.builder.botmaster.getLockByID(l).getLock(slavebuilder) b.setLocks([l]) step = Mock() step.return_value = step step.startStep.return_value = SUCCESS b.setStepFactories([(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(status, None, slavebuilder) self.assert_(('startStep', (b.remote, ), {}) not in step.method_calls) self.assert_(b.currentStep is None) self.assertEqual(b.result, EXCEPTION) self.assert_(('interrupt', ('stop it', ), {}) not in step.method_calls)
def acquireLocks(res=None): retval = Build.acquireLocks(b, res) b.stopBuild('stop it') return retval