コード例 #1
0
ファイル: test_db_builds.py プロジェクト: zware/buildbot
    def test_getBuildsForChange_OneCodebase(self):
        rows = [
            fakedb.Master(id=88, name="bar"),
            fakedb.Worker(id=13, name='one'),
            fakedb.Builder(id=77, name='A'),
            fakedb.SourceStamp(id=234, created_at=CREATED_AT, revision="aaa"),
            fakedb.Change(changeid=14, codebase='A', sourcestampid=234),
            fakedb.Buildset(id=30,
                            reason='foo',
                            submitted_at=1300305712,
                            results=1),
            fakedb.BuildsetSourceStamp(sourcestampid=234, buildsetid=30),
            fakedb.BuildRequest(id=19,
                                buildsetid=30,
                                builderid=77,
                                priority=13,
                                submitted_at=1300305712,
                                results=1,
                                complete=0,
                                complete_at=None),
            fakedb.Build(id=50,
                         buildrequestid=19,
                         number=5,
                         masterid=88,
                         builderid=77,
                         state_string="test",
                         workerid=13,
                         started_at=1304262222,
                         results=1),
        ]

        expected = [{
            'id': 50,
            'number': 5,
            'builderid': 77,
            'buildrequestid': 19,
            'workerid': 13,
            'masterid': 88,
            'started_at': epoch2datetime(1304262222),
            'complete_at': None,
            'state_string': 'test',
            'results': 1
        }]

        return self.do_test_getBuildsForChange(rows, 14, expected)
コード例 #2
0
    def testRebuildBuildrequest(self):
        self.master.db.insertTestData([
            fakedb.Builder(id=77, name='builder'),
            fakedb.Master(id=88),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Buildset(id=8822),
            fakedb.SourceStamp(id=234),
            fakedb.BuildsetSourceStamp(buildsetid=8822, sourcestampid=234),
            fakedb.BuildRequest(id=82, buildsetid=8822, builderid=77),
            fakedb.BuildsetProperty(buildsetid=8822, property_name='prop1',
                                    property_value='["one", "fake1"]'),
            fakedb.BuildsetProperty(buildsetid=8822, property_name='prop2',
                                    property_value='["two", "fake2"]'),
        ])
        buildrequest = yield self.master.data.get(('buildrequests', 82))
        new_bsid, brid_dict = yield self.rtype.rebuildBuildrequest(buildrequest)

        self.assertEqual(list(brid_dict.keys()), [77])
        buildrequest = yield self.master.data.get(('buildrequests', brid_dict[77]))
        # submitted_at is the time of the test, so better not depend on it
        self.assertTrue(buildrequest['submitted_at'] is not None)
        buildrequest['submitted_at'] = None
        self.assertEqual(buildrequest, {'buildrequestid': 1001, 'complete': False, 'waited_for': False,
                                        'claimed_at': None, 'results': -1, 'claimed': False,
                                        'buildsetid': 200, 'complete_at': None, 'submitted_at': None,
                                        'builderid': 77, 'claimed_by_masterid': None, 'priority': 0,
                                        'properties': None})
        buildset = yield self.master.data.get(('buildsets', new_bsid))
        oldbuildset = yield self.master.data.get(('buildsets', 8822))

        # assert same sourcestamp
        self.assertEqual(buildset['sourcestamps'], oldbuildset['sourcestamps'])
        buildset['sourcestamps'] = None
        self.assertTrue(buildset['submitted_at'] is not None)
        buildset['submitted_at'] = None
        self.assertEqual(buildset, {'bsid': 200, 'complete_at': None, 'submitted_at': None,
                                    'sourcestamps': None, 'parent_buildid': None,
                                    'results': -1, 'parent_relationship': None,
                                    'reason': u'rebuild',
                                    'external_idstring': u'extid',
                                    'complete': False})

        properties = yield self.master.data.get(('buildsets', new_bsid, 'properties'))
        self.assertEqual(
            properties, {u'prop1': (u'one', u'fake1'), u'prop2': (u'two', u'fake2')})
コード例 #3
0
    def setupBuildResults(self, results, wantPreviousBuild=False):
        # this testsuite always goes through setupBuildResults so that
        # the data is sure to be the real data schema known coming from data api

        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='sl'),
            fakedb.Buildset(id=98, results=results, reason="testReason1"),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=80),
            fakedb.Build(id=20, number=0, builderid=80, buildrequestid=11, workerid=13,
                         masterid=92, results=results),
            fakedb.Step(id=50, buildid=20, number=5, name='make'),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234, patchid=99),
            fakedb.Change(changeid=13, branch=u'trunk', revision=u'9283', author='me@foo',
                          repository=u'svn://...', codebase=u'cbsvn',
                          project=u'world-domination', sourcestampid=234),
            fakedb.Log(id=60, stepid=50, name='stdio', slug='stdio', type='s',
                       num_lines=7),
            fakedb.LogChunk(logid=60, first_line=0, last_line=1, compressed=0,
                            content=u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).'),
            fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk',
                         patch_author='him@foo', patch_comment='foo', subdir='/foo',
                         patchlevel=3),
        ])
        for _id in (20,):
            self.db.insertTestData([
                fakedb.BuildProperty(buildid=_id, name="workername", value="sl"),
                fakedb.BuildProperty(buildid=_id, name="reason", value="because"),
            ])
        res = yield utils.getDetailsForBuildset(self.master, 98, wantProperties=True,
                                                wantPreviousBuild=wantPreviousBuild)
        builds = res['builds']
        buildset = res['buildset']

        @defer.inlineCallbacks
        def getChangesForBuild(buildid):
            assert buildid == 20
            ch = yield self.master.db.changes.getChange(13)
            defer.returnValue([ch])

        self.master.db.changes.getChangesForBuild = getChangesForBuild
        defer.returnValue((buildset, builds))
コード例 #4
0
    def test_fromSsdict_changes(self):
        master = mock.Mock()
        master.db = fakedb.FakeDBConnector(self)
        master.db.insertTestData([
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://...',
                          project='world-domination'),
            fakedb.Change(changeid=14,
                          branch='trunk',
                          revision='9284',
                          repository='svn://...',
                          project='world-domination'),
            fakedb.Change(changeid=15,
                          branch='trunk',
                          revision='9284',
                          repository='svn://...',
                          project='world-domination'),
            fakedb.SourceStamp(id=234,
                               branch='trunk',
                               revision='9284',
                               repository='svn://...',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=234, changeid=14),
            fakedb.SourceStampChange(sourcestampid=234, changeid=13),
            fakedb.SourceStampChange(sourcestampid=234, changeid=15),
        ])
        # use getSourceStamp to minimize the risk from changes to the format of
        # the ssdict
        d = master.db.sourcestamps.getSourceStamp(234)
        d.addCallback(
            lambda ssdict: sourcestamp.SourceStamp.fromSsdict(master, ssdict))

        def check(ss):
            self.assertEqual(ss.ssid, 234)
            self.assertEqual(ss.branch, 'trunk')
            self.assertEqual(ss.revision, '9284')
            self.assertEqual(ss.patch, None)
            self.assertEqual([ch.number for ch in ss.changes], [13, 14, 15])
            self.assertEqual(ss.project, 'world-domination')
            self.assertEqual(ss.repository, 'svn://...')

        d.addCallback(check)
        return d
コード例 #5
0
    def test_pruneChanges(self):
        d = self.insertTestData([
            fakedb.Object(id=29),
            fakedb.SourceStamp(id=234),

            fakedb.Change(changeid=11),

            fakedb.Change(changeid=12),
            fakedb.SchedulerChange(objectid=29, changeid=12),
            fakedb.SourceStampChange(sourcestampid=234, changeid=12),
            ] +

            self.change13_rows + [
            fakedb.SchedulerChange(objectid=29, changeid=13),
            ] +

            self.change14_rows + [
            fakedb.SchedulerChange(objectid=29, changeid=14),

            fakedb.Change(changeid=15),
            fakedb.SourceStampChange(sourcestampid=234, changeid=15),
            ]
        )

        # pruning with a horizon of 2 should delete changes 11, 12 and 13
        d.addCallback(lambda _ : self.db.changes.pruneChanges(2))
        def check(_):
            def thd(conn):
                results = {}
                for tbl_name in ('scheduler_changes', 'sourcestamp_changes',
                                 'change_files', 'change_properties',
                                 'changes'):
                    tbl = self.db.model.metadata.tables[tbl_name]
                    r = conn.execute(sa.select([tbl.c.changeid]))
                    results[tbl_name] = sorted([ r[0] for r in r.fetchall() ])
                self.assertEqual(results, {
                    'scheduler_changes': [14],
                    'sourcestamp_changes': [15],
                    'change_files': [14],
                    'change_properties': [],
                    'changes': [14, 15],
                })
            return self.db.pool.do(thd)
        d.addCallback(check)
        return d
コード例 #6
0
    def test_bogus_row_jsoned_list(self):
        d = self.insertTestData([
            fakedb.SourceStamp(id=10),
            fakedb.ChangeProperty(changeid=13,
                                  property_name='devel',
                                  property_value='[1, 2]'),
            fakedb.Change(changeid=13, sourcestampid=10),
        ])

        @d.addCallback
        def get13(_):
            return self.db.changes.getChange(13)

        @d.addCallback
        def check13(c):
            self.assertEqual(c['properties'], dict(devel=([1, 2], 'Change')))

        return d
コード例 #7
0
ファイル: test_db_buildsets.py プロジェクト: JPMMaia/buildbot
    def insert_test_getRecentBuildsets_data(self):
        return self.insertTestData([
            fakedb.SourceStamp(id=91, branch='branch_a', repository='repo_a'),

            fakedb.Buildset(id=91, complete=0,
                            complete_at=298297875, results=-1, submitted_at=266761875,
                            external_idstring='extid', reason='rsn1'),
            fakedb.BuildsetSourceStamp(buildsetid=91, sourcestampid=91),
            fakedb.Buildset(id=92, complete=1,
                            complete_at=298297876, results=7, submitted_at=266761876,
                            external_idstring='extid', reason='rsn2'),
            fakedb.BuildsetSourceStamp(buildsetid=92, sourcestampid=91),

            # buildset unrelated to the change
            fakedb.Buildset(id=93, complete=1,
                            complete_at=298297877, results=7, submitted_at=266761877,
                            external_idstring='extid', reason='rsn2'),
        ])
コード例 #8
0
ファイル: test_data_buildsets.py プロジェクト: zware/buildbot
 def setUp(self):
     self.setUpTestReactor()
     self.master = fakemaster.make_master(self,
                                          wantMq=True,
                                          wantDb=True,
                                          wantData=True)
     self.rtype = buildsets.Buildset(self.master)
     return self.master.db.insertTestData([
         fakedb.SourceStamp(id=234,
                            branch='br',
                            codebase='cb',
                            project='pr',
                            repository='rep',
                            revision='rev',
                            created_at=89834834),
         fakedb.Builder(id=42, name='bldr1'),
         fakedb.Builder(id=43, name='bldr2'),
     ])
コード例 #9
0
    def test_collapseRequests_no_other_request(self):

        def collapseRequests_fn(builder, brdict1, brdict2):
            # Allow all requests
            self.fail("Should never be called")
            return True

        self.bldr.getCollapseRequestsFn = lambda: collapseRequests_fn
        rows = [
            fakedb.Builder(id=77, name='A'),
            fakedb.SourceStamp(id=234, codebase='A'),
            fakedb.Change(changeid=14, codebase='A', sourcestampid=234),
            fakedb.Buildset(id=30, reason='foo',
                            submitted_at=1300305712, results=-1),
            fakedb.BuildsetSourceStamp(sourcestampid=234, buildsetid=30),
            fakedb.BuildRequest(id=19, buildsetid=30, builderid=77,
                                priority=13, submitted_at=1300305712, results=-1),
        ]
        self.do_request_collapse(rows, [19], [])
コード例 #10
0
    def test_getSourceStamp_simple_None(self):
        "check that NULL branch and revision are handled correctly"
        d = self.insertTestData([
            fakedb.SourceStamp(id=234,
                               branch=None,
                               revision=None,
                               repository='rep',
                               codebase='cb',
                               project='prj'),
        ])
        d.addCallback(lambda _: self.db.sourcestamps.getSourceStamp(234))

        def check(ssdict):
            validation.verifyDbDict(self, 'ssdict', ssdict)
            self.assertEqual((ssdict['branch'], ssdict['revision']),
                             (None, None))

        d.addCallback(check)
        return d
コード例 #11
0
    def do_test_nextWorker(self,
                           nextWorker,
                           exp_choice=None,
                           exp_warning=False):
        def makeBuilderConfig():
            return config.BuilderConfig(name='bldrconf',
                                        workernames=['wk1', 'wk2'],
                                        builddir='bdir',
                                        factory=factory.BuildFactory(),
                                        nextWorker=nextWorker)

        if exp_warning:
            with assertProducesWarning(
                    config.ConfigWarning,
                    message_pattern=r"nextWorker now takes a 3rd argument"):
                builder_config = makeBuilderConfig()
        else:
            builder_config = makeBuilderConfig()

        self.bldr = yield self.createBuilder('B',
                                             builderid=78,
                                             builder_config=builder_config)
        for i in range(4):
            self.addWorkers({'test-worker%d' % i: 1})

        rows = [
            fakedb.SourceStamp(id=21),
            fakedb.Builder(id=78, name='B'),
            fakedb.Buildset(id=12, reason='because'),
            fakedb.BuildsetSourceStamp(sourcestampid=21, buildsetid=12),
            fakedb.BuildRequest(id=12, buildsetid=12, builderid=78),
        ]

        if exp_choice is None:
            exp_claims = []
            exp_builds = []
        else:
            exp_claims = [12]
            exp_builds = [('test-worker%d' % exp_choice, [12])]

        yield self.do_test_maybeStartBuildsOnBuilder(rows=rows,
                                                     exp_claims=exp_claims,
                                                     exp_builds=exp_builds)
コード例 #12
0
    def setUp(self):
        self.botmaster = mock.Mock(name='botmaster')
        self.botmaster.builders = {}
        self.master = self.botmaster.master = mock.Mock(name='master')
        self.master.db = fakedb.FakeDBConnector(self)

        class getCache(object):
            def get_cache(self):
                return self

            def get(self, name):
                return

        self.master.caches = fakemaster.FakeCaches()
        self.brd = buildrequestdistributor.BuildRequestDistributor(
            self.botmaster)
        self.brd.BuildChooser = BasicBuildChooser
        self.brd.startService()

        self.startedBuilds = []

        # TODO: this is a terrible way to detect the "end" of the test -
        # it regularly completes too early after a simple modification of
        # a test.  Is there a better way?
        self.quiet_deferred = defer.Deferred()

        def _quiet():
            if self.quiet_deferred:
                d, self.quiet_deferred = self.quiet_deferred, None
                d.callback(None)
            else:
                self.fail("loop has already gone quiet once")

        self.brd._quiet = _quiet

        self.bldr = self.createBuilder('A')

        # a collection of rows that would otherwise clutter up every test
        self.base_rows = [
            fakedb.SourceStampSet(id=21),
            fakedb.SourceStamp(id=21, sourcestampsetid=21),
            fakedb.Buildset(id=11, reason='because', sourcestampsetid=21),
        ]
コード例 #13
0
    def test_fromBrdict_submittedAt_NULL(self):
        master = fakemaster.make_master(self, wantData=True, wantDb=True)
        master.db.insertTestData([
            fakedb.Builder(id=77, name='bldr'),
            fakedb.SourceStamp(id=234, branch='trunk',
                               revision='9284', repository='svn://...',
                               project='world-domination'),
            fakedb.Buildset(id=539, reason='triggered'),
            fakedb.BuildsetSourceStamp(buildsetid=539, sourcestampid=234),
            fakedb.BuildRequest(id=288, buildsetid=539, builderid=77,
                                priority=13, submitted_at=None),
        ])
        # use getBuildRequest to minimize the risk from changes to the format
        # of the brdict
        brdict = yield master.db.buildrequests.getBuildRequest(288)
        br = yield buildrequest.BuildRequest.fromBrdict(master, brdict)

        # remaining fields assumed to be checked in test_fromBrdict
        self.assertEqual(br.submittedAt, None)
コード例 #14
0
ファイル: test_master.py プロジェクト: ctemplin/buildbot
    def test_pollDatabaseBuildRequests_new(self):
        self.db.insertTestData([
            fakedb.SourceStamp(id=127),
            fakedb.Buildset(id=99, sourcestampid=127),
            fakedb.BuildRequest(id=19, buildsetid=99, buildername='9teen'),
            fakedb.BuildRequest(id=20, buildsetid=99, buildername='twenty')
        ])
        d = self.master.pollDatabaseBuildRequests()

        def check(_):
            self.assertEqual(
                sorted(self.gotten_buildrequest_additions),
                sorted([
                    dict(bsid=99, brid=19, buildername='9teen'),
                    dict(bsid=99, brid=20, buildername='twenty')
                ]))

        d.addCallback(check)
        return d
コード例 #15
0
 def setUp(self):
     # a collection of rows that would otherwise clutter up every test
     master_id = fakedb.FakeBuildRequestsComponent.MASTER_ID
     self.base_rows = [
         fakedb.SourceStamp(id=21),
         fakedb.Buildset(id=11, reason='because', sourcestampid=21),
         fakedb.BuildRequest(id=111, submitted_at=1000,
                     buildername='bldr1', buildsetid=11),
         fakedb.BuildRequest(id=222, submitted_at=2000,
                     buildername='bldr1', buildsetid=11),
         fakedb.BuildRequestClaim(brid=222, objectid=master_id,
                     claimed_at=2001),
         fakedb.BuildRequest(id=333, submitted_at=3000,
                     buildername='bldr1', buildsetid=11),
         fakedb.BuildRequest(id=444, submitted_at=2500,
                     buildername='bldr2', buildsetid=11),
         fakedb.BuildRequestClaim(brid=444, objectid=master_id,
                     claimed_at=2501),
     ]
コード例 #16
0
    def do_test(self, scheduler_name, expect_subscription,
            result, expect_buildset):
        sched = self.makeScheduler()
        sched.startService()
        callbacks = self.master.getSubscriptionCallbacks()

        # pretend we saw a buildset with a matching name
        self.db.insertTestData([
            fakedb.SourceStamp(id=93, sourcestampsetid=1093, revision='555',
                            branch='master', project='proj', repository='repo',
                            codebase = 'cb'),
            fakedb.Buildset(id=44, sourcestampsetid=1093),
            ])
        callbacks['buildsets'](bsid=44,
                properties=dict(scheduler=(scheduler_name, 'Scheduler')))

        # check whether scheduler is subscribed to that buildset
        if expect_subscription:
            self.assertBuildsetSubscriptions([44])
        else:
            self.assertBuildsetSubscriptions([])

        # pretend that the buildset is finished
        self.db.buildsets.fakeBuildsetCompletion(bsid=44, result=result)
        callbacks['buildset_completion'](44, result)

        # and check whether a buildset was added in response
        if expect_buildset:
            self.db.buildsets.assertBuildsets(2)
            bsids = self.db.buildsets.allBuildsetIds()
            bsids.remove(44)
            self.db.buildsets.assertBuildset(bsids[0],
                    dict(external_idstring=None,
                         properties=[('scheduler', ('n', 'Scheduler'))],
                         reason='downstream', sourcestampsetid = 1093),
                    {'cb':
                     dict(revision='555', branch='master', project='proj',
                         repository='repo', codebase='cb',
                         sourcestampsetid = 1093)
                    })
        else:
            self.db.buildsets.assertBuildsets(1) # only the one we added above
コード例 #17
0
    def test_brdictToBuildRequest(self):
        wfd = defer.waitForDeferred(self.makeBuilder())
        yield wfd
        wfd.getResult()

        # set up all of the data required for a BuildRequest object
        wfd = defer.waitForDeferred(
            self.db.insertTestData([
                fakedb.SourceStampSet(id=234),
                fakedb.SourceStamp(id=234, sourcestampsetid=234),
                fakedb.Buildset(id=30,
                                sourcestampsetid=234,
                                reason='foo',
                                submitted_at=1300305712,
                                results=-1),
                fakedb.BuildRequest(id=19,
                                    buildsetid=30,
                                    buildername='bldr',
                                    priority=13,
                                    submitted_at=1300305712,
                                    results=-1),
            ]))
        yield wfd
        wfd.getResult()

        wfd = defer.waitForDeferred(self.db.buildrequests.getBuildRequest(19))
        yield wfd
        brdict = wfd.getResult()

        wfd = defer.waitForDeferred(self.bldr._brdictToBuildRequest(brdict))
        yield wfd
        br = wfd.getResult()

        # just check that the BuildRequest looks reasonable -
        # test_process_buildrequest checks the whole thing
        self.assertEqual(br.reason, 'foo')

        # and check that the cross-pointers are correct
        self.assertIdentical(br.brdict, brdict)
        self.assertIdentical(brdict['brobj'], br)

        self.bldr._breakBrdictRefloops([brdict])
コード例 #18
0
 def test_getSourceStamp_patch(self):
     d = self.insertTestData([
         fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk',
             patch_author='bar', patch_comment='foo', subdir='/foo',
             patchlevel=3),
         fakedb.SourceStampSet(id=234),
         fakedb.SourceStamp(id=234, sourcestampsetid=234, patchid=99),
     ])
     d.addCallback(lambda _ :
             self.db.sourcestamps.getSourceStamp(234))
     def check(ssdict):
         self.assertEqual(dict((k,v) for k,v in ssdict.iteritems()
                               if k.startswith('patch_')),
                          dict(patch_body='hello, world',
                               patch_level=3,
                               patch_author='bar',
                               patch_comment='foo',
                               patch_subdir='/foo'))
     d.addCallback(check)
     return d
コード例 #19
0
    def test_getUpstreamBuildsets_missing(self):
        sched = self.makeScheduler()

        # insert some state, with more bsids than exist
        self.db.insertTestData([
            fakedb.SourceStamp(id=1234),
            fakedb.Buildset(id=11),
            fakedb.Buildset(id=13),
            fakedb.BuildsetSourceStamp(buildsetid=13, sourcestampid=1234),
            fakedb.Object(id=OBJECTID),
            fakedb.ObjectState(objectid=OBJECTID,
                               name='upstream_bsids', value_json='[11,12,13]'),
        ])

        # check return value (missing 12)
        self.assertEqual((yield sched._getUpstreamBuildsets()),
                         [(11, [], False, -1), (13, [1234], False, -1)])

        # and check that it wrote the correct value back to the state
        self.db.state.assertState(OBJECTID, upstream_bsids=[11, 13])
コード例 #20
0
    def test_getSourceStamp_patch(self):
        yield self.insertTestData([
            fakedb.Patch(id=99,
                         patch_base64='aGVsbG8sIHdvcmxk',
                         patch_author='bar',
                         patch_comment='foo',
                         subdir='/foo',
                         patchlevel=3),
            fakedb.SourceStamp(id=234, patchid=99),
        ])
        ssdict = yield self.db.sourcestamps.getSourceStamp(234)

        validation.verifyDbDict(self, 'ssdict', ssdict)
        self.assertEqual(
            dict((k, v) for k, v in ssdict.items() if k.startswith('patch_')),
            dict(patch_body=b'hello, world',
                 patch_level=3,
                 patch_author='bar',
                 patch_comment='foo',
                 patch_subdir='/foo'))
コード例 #21
0
    def test_bogus_row_no_source(self):
        d = self.insertTestData([
            fakedb.SourceStamp(id=10),
            fakedb.ChangeProperty(changeid=13,
                                  property_name='devel',
                                  property_value='"no source"'),
            fakedb.Change(changeid=13, sourcestampid=10),
        ])

        def get13(_):
            return self.db.changes.getChange(13)

        d.addCallback(get13)

        def check13(c):
            self.assertEqual(c['properties'],
                             dict(devel=('no source', 'Change')))

        d.addCallback(check13)
        return d
コード例 #22
0
    def setUp(self):
        self.now = 9272359
        self.clock = task.Clock()
        self.clock.advance(self.now)

        d = self.setUpConnectorComponent(
            table_names=[ 'patches', 'changes', 'sourcestamp_changes',
                'buildsets', 'buildset_properties', 'schedulers',
                'buildrequests', 'scheduler_upstream_buildsets',
                'sourcestamps' ])

        def finish_setup(_):
            self.db.buildsets = buildsets.BuildsetsConnectorComponent(self.db)
        d.addCallback(finish_setup)

        # set up a sourcestamp with id 234 for use below
        d.addCallback(lambda _ :
            self.insertTestData([ fakedb.SourceStamp(id=234) ]))

        return d
コード例 #23
0
    def test_fromBrdict(self):
        master = fakemaster.make_master(testcase=self,
                                        wantData=True, wantDb=True)
        master.db.insertTestData([
            fakedb.Builder(id=77, name='bldr'),
            fakedb.SourceStamp(id=234, branch='trunk',
                               revision='9284', repository='svn://...',
                               project='world-domination'),
            fakedb.Change(changeid=13, branch='trunk', revision='9283',
                          repository='svn://...', project='world-domination',
                          sourcestampid=234),
            fakedb.Buildset(id=539, reason='triggered'),
            fakedb.BuildsetSourceStamp(buildsetid=539, sourcestampid=234),
            fakedb.BuildsetProperty(buildsetid=539, property_name='x',
                                    property_value='[1, "X"]'),
            fakedb.BuildsetProperty(buildsetid=539, property_name='y',
                                    property_value='[2, "Y"]'),
            fakedb.BuildRequest(id=288, buildsetid=539, builderid=77,
                                priority=13, submitted_at=1200000000),
        ])
        # use getBuildRequest to minimize the risk from changes to the format
        # of the brdict
        d = master.db.buildrequests.getBuildRequest(288)
        d.addCallback(lambda brdict:
                      buildrequest.BuildRequest.fromBrdict(master, brdict))

        def check(br):
            # check enough of the source stamp to verify it found the changes
            self.assertEqual([ss.ssid for ss in itervalues(br.sources)], [234])

            self.assertEqual(br.reason, 'triggered')

            self.assertEqual(br.properties.getProperty('x'), 1)
            self.assertEqual(br.properties.getProperty('y'), 2)
            self.assertEqual(br.submittedAt, 1200000000)
            self.assertEqual(br.buildername, 'bldr')
            self.assertEqual(br.priority, 13)
            self.assertEqual(br.id, 288)
            self.assertEqual(br.bsid, 539)
        d.addCallback(check)
        return d
コード例 #24
0
    def setUp(self):
        self.setUpTestReactor()
        self.setUpBuilderMixin()

        # a collection of rows that would otherwise clutter up every test
        master_id = fakedb.FakeBuildRequestsComponent.MASTER_ID
        self.base_rows = [
            fakedb.SourceStamp(id=21),
            fakedb.Buildset(id=11, reason='because'),
            fakedb.BuildsetSourceStamp(buildsetid=11, sourcestampid=21),
            fakedb.Builder(id=77, name='bldr1'),
            fakedb.Builder(id=78, name='bldr2'),
            fakedb.Builder(id=182, name='foo@bar'),
            fakedb.BuildRequest(id=111,
                                submitted_at=1000,
                                builderid=77,
                                buildsetid=11),
            fakedb.BuildRequest(id=222,
                                submitted_at=2000,
                                builderid=77,
                                buildsetid=11),
            fakedb.BuildRequestClaim(brid=222,
                                     masterid=master_id,
                                     claimed_at=2001),
            fakedb.BuildRequest(id=333,
                                submitted_at=3000,
                                builderid=77,
                                buildsetid=11),
            fakedb.BuildRequest(id=444,
                                submitted_at=2500,
                                builderid=78,
                                buildsetid=11),
            fakedb.BuildRequestClaim(brid=444,
                                     masterid=master_id,
                                     claimed_at=2501),
            fakedb.BuildRequest(id=555,
                                submitted_at=2800,
                                builderid=182,
                                buildsetid=11),
        ]
        yield self.db.insertTestData(self.base_rows)
コード例 #25
0
    def test_mergeRequests(self):
        yield self.makeBuilder()

        # set up all of the data required for a BuildRequest object
        yield self.db.insertTestData([
                fakedb.SourceStampSet(id=234),
                fakedb.SourceStamp(id=234, sourcestampsetid=234),
                fakedb.Buildset(id=30, sourcestampsetid=234, reason='foo',
                    submitted_at=1300305712, results=-1),
                fakedb.BuildRequest(id=19, buildsetid=30, buildername='bldr',
                    priority=13, submitted_at=1300305712, results=-1),
                fakedb.BuildRequest(id=20, buildsetid=30, buildername='bldr',
                    priority=13, submitted_at=1300305712, results=-1),
                fakedb.BuildRequest(id=21, buildsetid=30, buildername='bldr',
                    priority=13, submitted_at=1300305712, results=-1),
            ])

        brdicts = yield defer.gatherResults([
                self.db.buildrequests.getBuildRequest(id)
                for id in (19, 20, 21)
            ])

        def mergeRequests_fn(builder, breq, other):
            # merge evens with evens, odds with odds
            return breq.id % 2 == other.id % 2

        # check odds
        odds = yield self.bldr._mergeRequests(brdicts[0],
                                brdicts, mergeRequests_fn)
        self.assertEqual(odds, [ brdicts[0], brdicts[2] ])

        # check evens
        evens = yield self.bldr._mergeRequests(brdicts[1],
                                brdicts, mergeRequests_fn)
        self.assertEqual(evens, [ brdicts[1] ])

        # check original relative order of requests within brdicts is maintained
        merged = yield self.bldr._mergeRequests(brdicts[2],
                                                brdicts, mergeRequests_fn)
        self.assertEqual(merged, [brdicts[0], brdicts[2]],
                         'relative order of merged requests was not maintained')
コード例 #26
0
    def test_mergeRequests(self):
        self.makeBuilder()
        # set up all of the data required for a BuildRequest object
        wfd = defer.waitForDeferred(
            self.db.insertTestData([
                fakedb.SourceStamp(id=234),
                fakedb.Buildset(id=30, sourcestampid=234, reason='foo',
                    submitted_at=1300305712, results=-1),
                fakedb.BuildRequest(id=19, buildsetid=30, buildername='bldr',
                    priority=13, submitted_at=1300305712, results=-1),
                fakedb.BuildRequest(id=20, buildsetid=30, buildername='bldr',
                    priority=13, submitted_at=1300305712, results=-1),
                fakedb.BuildRequest(id=21, buildsetid=30, buildername='bldr',
                    priority=13, submitted_at=1300305712, results=-1),
            ]))
        yield wfd
        wfd.getResult()

        wfd = defer.waitForDeferred(
            defer.gatherResults([
                self.db.buildrequests.getBuildRequest(id)
                for id in (19, 20, 21)
            ]))
        yield wfd
        brdicts = wfd.getResult()

        def mergeRequests_fn(builder, breq, other):
            # merge evens with evens, odds with odds
            return breq.id % 2 == other.id % 2

        # check odds
        wfd = defer.waitForDeferred(
            self.bldr._mergeRequests(brdicts[0], brdicts, mergeRequests_fn))
        yield wfd
        self.assertEqual(wfd.getResult(), [ brdicts[0], brdicts[2] ])

        # check evens
        wfd = defer.waitForDeferred(
            self.bldr._mergeRequests(brdicts[1], brdicts, mergeRequests_fn))
        yield wfd
        self.assertEqual(wfd.getResult(), [ brdicts[1] ])
コード例 #27
0
    def setUp(self):
        d = self.setUpConnectorComponent(
            table_names=[ 'patches', 'changes', 'sourcestamp_changes',
                'buildsets', 'buildset_properties', 'buildrequests',
                'sourcestamps' ])

        def finish_setup(_):
            self.db.buildrequests = \
                    buildrequests.BuildRequestsConnectorComponent(self.db)
            self.db.master.master_name = self.MASTER_NAME
            self.db.master.master_incarnation = self.MASTER_INCARN
        d.addCallback(finish_setup)

        # set up a sourcestamp and buildset for use below
        d.addCallback(lambda _ :
            self.insertTestData([
                fakedb.SourceStamp(id=234),
                fakedb.Buildset(id=self.BSID, sourcestampid=234),
            ]))

        return d
コード例 #28
0
    def test_addBuildsetForSourceStamp_properties(self):
        props = properties.Properties(xxx="yyy")
        sched = self.makeScheduler(name='n', builderNames=['b'])
        d = self.db.insertTestData([
            fakedb.SourceStampSet(id=1091),
            fakedb.SourceStamp(id=91,
                               sourcestampsetid=1091,
                               branch='fixins',
                               revision='abc',
                               patchid=None,
                               repository='r',
                               codebase='cb',
                               project='p'),
        ])
        d.addCallback(lambda _: sched.addBuildsetForSourceStamp(
            reason='whynot', setid=1091, properties=props))

        def check(xxx_todo_changeme11):
            (bsid, brids) = xxx_todo_changeme11
            self.db.buildsets.assertBuildset(
                bsid,
                dict(reason='whynot',
                     brids=brids,
                     external_idstring=None,
                     properties=[
                         ('scheduler', ('n', 'Scheduler')),
                         ('xxx', ('yyy', 'TEST')),
                     ],
                     sourcestampsetid=1091), {
                         'cb':
                         dict(branch='fixins',
                              revision='abc',
                              repository='r',
                              codebase='cb',
                              project='p',
                              sourcestampsetid=1091)
                     })

        d.addCallback(check)
        return d
コード例 #29
0
    def setUp(self):
        self.botmaster = mock.Mock(name='botmaster')
        self.botmaster.builders = {}
        self.builders = {}

        def prioritizeBuilders(master, builders):
            # simple sort-by-name by default
            return sorted(builders, key=lambda b1: b1.name)

        self.master = self.botmaster.master = fakemaster.make_master(
            testcase=self, wantData=True, wantDb=True)
        self.master.caches = fakemaster.FakeCaches()
        self.master.config.prioritizeBuilders = prioritizeBuilders
        self.brd = buildrequestdistributor.BuildRequestDistributor(
            self.botmaster)
        self.brd.parent = self.botmaster
        self.brd.startService()

        # TODO: this is a terrible way to detect the "end" of the test -
        # it regularly completes too early after a simple modification of
        # a test.  Is there a better way?
        self.quiet_deferred = defer.Deferred()

        def _quiet():
            if self.quiet_deferred:
                d, self.quiet_deferred = self.quiet_deferred, None
                d.callback(None)
            else:
                self.fail("loop has already gone quiet once")

        self.brd._quiet = _quiet

        # a collection of rows that would otherwise clutter up every test
        self.base_rows = [
            fakedb.SourceStamp(id=21),
            fakedb.Builder(id=77, name='A'),
            fakedb.Buildset(id=11, reason='because'),
            fakedb.BuildsetSourceStamp(sourcestampid=21, buildsetid=11),
        ]
コード例 #30
0
    def setUp(self):
        self.MASTER_ID = fakedb.FakeBuildRequestsComponent.MASTER_ID
        d = self.setUpConnectorComponent(table_names=[
            'patches', 'changes', 'sourcestamp_changes', 'buildsets',
            'buildset_properties', 'buildrequests', 'buildrequest_claims',
            'sourcestamps'
        ])

        def finish_setup(_):
            self.db.buildrequests = \
                    buildrequests.BuildRequestsConnectorComponent(self.db)
            self.db.master.getObjectId = lambda: defer.succeed(self.MASTER_ID)

        d.addCallback(finish_setup)

        # set up a sourcestamp and buildset for use below
        d.addCallback(lambda _: self.insertTestData([
            fakedb.SourceStamp(id=234),
            fakedb.Buildset(id=self.BSID, sourcestampid=234),
        ]))

        return d