def testSuccess(self): S = buildset.BuildSet a,b = FakeBuilder(), FakeBuilder() # this time, both builds succeed source = sourcestamp.SourceStamp() s = S(["a","b"], source, "forced build") s.start([a,b]) st = s.status self.failUnlessEqual(st.getSourceStamp(), source) self.failUnlessEqual(st.getReason(), "forced build") self.failUnlessEqual(st.getBuilderNames(), ["a","b"]) self.failIf(st.isFinished()) builderstatus_a = builder.BuilderStatus("a") bsa = builder.BuildStatus(builderstatus_a, 1) bsa.setResults(builder.SUCCESS) a.requests[0].finished(bsa) builderstatus_b = builder.BuilderStatus("b") bsb = builder.BuildStatus(builderstatus_b, 1) bsb.setResults(builder.SUCCESS) b.requests[0].finished(bsb) self.failUnless(st.isFinished()) self.failUnlessEqual(st.getResults(), builder.SUCCESS)
def testStepStatistics(self): status = builder.BuildStatus(builder.BuilderStatus("test"), 123) status.addStepWithName('step1') status.addStepWithName('step2') status.addStepWithName('step3') status.addStepWithName('step4') steps = status.getSteps() (step1, step2, step3, step4) = steps step1.setStatistic('test-prop', 1) step3.setStatistic('test-prop', 2) step4.setStatistic('test-prop', 4) step1.setStatistic('other-prop', 27) # Just to have some other properties around self.failUnlessEqual(step1.getStatistic('test-prop'), 1, 'Retrieve an existing property') self.failUnlessEqual(step1.getStatistic('test-prop', 99), 1, "Don't default an existing property") self.failUnlessEqual(step2.getStatistic('test-prop', 99), 99, 'Default a non-existant property') self.failUnlessEqual( status.getSummaryStatistic('test-prop', operator.add), 7, 'Sum property across the build') self.failUnlessEqual( status.getSummaryStatistic('test-prop', operator.add, 13), 20, 'Sum property across the build with initial value')
def testAB(self): self.setupSimple() c = Change('author', ['some/file.dtd'], 'comment', branch='dir', properties={'locale': 'ab'}) c.number = 1 self.scheduler.addChange(c) self.failUnlessEqual(len(self.master.sets), 1) bset = self.master.sets[0] props = bset.getProperties() self.assertEqual(props['locale'], 'ab') self.assertEqual(props['branch'], 'dir') self.assertEqual(props['tree'], 'dir-compare') self.failUnlessEqual(bset.builderNames, ['dir-compare']) ftb = FakeBuilder('dir-compare') bset.start([ftb]) self.failUnlessEqual(len(ftb.requests), 1) st = bset.status self.failIf(st.isFinished()) builder = builderstatus.BuilderStatus('dir-compare') build = builderstatus.BuildStatus(builder, 1) build.setResults(builderstatus.SUCCESS) ftb.requests[0].finished(build) self.failUnless(st.isFinished())
def test_d_ini(self): self.setupSimple() c = Change('author', ['test-app/locales/l10n.ini'], 'comment', branch='test-branch') c.number = 1 self.scheduler.addChange(c) c = Change('author', ['test-app/locales/en-US/app.dtd'], 'comment', branch='test-branch') c.number = 2 self.scheduler.addChange(c) self.failUnlessEqual(len(self.master.sets), 1) bset = self.master.sets[0] self.failUnlessEqual(bset.builderNames, ['tree-builds']) ftb = FakeBuilder('tree-builds') bset.start([ftb]) self.failUnlessEqual(len(ftb.requests), 1) st = bset.status self.failIf(st.isFinished()) builder = builderstatus.BuilderStatus('tree-builds') build = builderstatus.BuildStatus(builder, 1) build.setResults(builderstatus.SUCCESS) ftb.requests[0].finished(build) self.failUnless(st.isFinished()) self.failUnless(self.scheduler.dSubmitBuildsets) self.scheduler.dSubmitBuildsets.cancel() pendings = self.scheduler.pendings self.failUnlessEqual(len(pendings), 2) self.failUnlessEqual(len(pendings[('test', 'de')]), 1) self.failUnlessEqual(len(pendings[('test', 'fr')]), 1)
def setupBuildStepStatus(basedir): """Return a BuildStep with a suitable BuildStepStatus object, ready to use.""" os.mkdir(basedir) botmaster = None s0 = builder.Status(botmaster, basedir) s1 = s0.builderAdded("buildername", "buildername") s2 = builder.BuildStatus(s1, 1) s3 = builder.BuildStepStatus(s2) s3.setName("foostep") s3.started = True s3.stepStarted() return s3
def testAddResults(self): b = builder.BuildStatus(builder.BuilderStatus("test"), 12) testname = ("buildbot", "test", "test_status", "Results", "testAddResults") r1 = builder.TestResult( name=testname, results=builder.SUCCESS, text=["passed"], logs={'output': ""}, ) b.addTestResult(r1) res = b.getTestResults() self.failUnlessEqual(res.keys(), [testname]) t = res[testname] self.failUnless(interfaces.ITestResult.providedBy(t)) self.failUnlessEqual(t.getName(), testname) self.failUnlessEqual(t.getResults(), builder.SUCCESS) self.failUnlessEqual(t.getText(), ["passed"]) self.failUnlessEqual(t.getLogs(), {'output': ""})
def testBuildSet(self): S = buildset.BuildSet a,b = FakeBuilder(), FakeBuilder() # two builds, the first one fails, the second one succeeds. The # waitUntilSuccess watcher fires as soon as the first one fails, # while the waitUntilFinished watcher doesn't fire until all builds # are complete. source = sourcestamp.SourceStamp() s = S(["a","b"], source, "forced build") s.start([a,b]) self.failUnlessEqual(len(a.requests), 1) self.failUnlessEqual(len(b.requests), 1) r1 = a.requests[0] self.failUnlessEqual(r1.reason, s.reason) self.failUnlessEqual(r1.source, s.source) st = s.status self.failUnlessEqual(st.getSourceStamp(), source) self.failUnlessEqual(st.getReason(), "forced build") self.failUnlessEqual(st.getBuilderNames(), ["a","b"]) self.failIf(st.isFinished()) brs = st.getBuildRequests() self.failUnlessEqual(len(brs), 2) res = [] d1 = s.waitUntilSuccess() d1.addCallback(lambda r: res.append(("success", r))) d2 = s.waitUntilFinished() d2.addCallback(lambda r: res.append(("finished", r))) self.failUnlessEqual(res, []) # the first build finishes here, with FAILURE builderstatus_a = builder.BuilderStatus("a") bsa = builder.BuildStatus(builderstatus_a, 1) bsa.setResults(builder.FAILURE) a.requests[0].finished(bsa) # any FAILURE flunks the BuildSet immediately, so the # waitUntilSuccess deferred fires right away. However, the # waitUntilFinished deferred must wait until all builds have # completed. self.failUnlessEqual(len(res), 1) self.failUnlessEqual(res[0][0], "success") bss = res[0][1] self.failUnless(interfaces.IBuildSetStatus(bss, None)) self.failUnlessEqual(bss.getResults(), builder.FAILURE) # here we finish the second build builderstatus_b = builder.BuilderStatus("b") bsb = builder.BuildStatus(builderstatus_b, 1) bsb.setResults(builder.SUCCESS) b.requests[0].finished(bsb) # .. which ought to fire the waitUntilFinished deferred self.failUnlessEqual(len(res), 2) self.failUnlessEqual(res[1][0], "finished") self.failUnlessEqual(res[1][1], bss) # and finish the BuildSet overall self.failUnless(st.isFinished()) self.failUnlessEqual(st.getResults(), builder.FAILURE)