Exemplo n.º 1
0
    def test_pruneChanges(self):
        yield self.insertTestData([
            fakedb.Scheduler(id=29),
            fakedb.SourceStamp(id=234, branch='aa'),
            fakedb.SourceStamp(id=235, branch='bb'),
            fakedb.Change(changeid=11),
            fakedb.Change(changeid=12, sourcestampid=234),
            fakedb.SchedulerChange(schedulerid=29, changeid=12),
        ] + self.change13_rows + [
            fakedb.SchedulerChange(schedulerid=29, changeid=13),
        ] + self.change14_rows + [
            fakedb.SchedulerChange(schedulerid=29, changeid=14),
            fakedb.Change(changeid=15, sourcestampid=235),
        ]
        )

        # pruning with a horizon of 2 should delete changes 11, 12 and 13
        yield self.db.changes.pruneChanges(2)

        def thd(conn):
            results = {}
            for tbl_name in ('scheduler_changes', 'change_files',
                             'change_properties', 'changes'):
                tbl = self.db.model.metadata.tables[tbl_name]
                res = conn.execute(sa.select([tbl.c.changeid]))
                results[tbl_name] = sorted(
                    [row[0] for row in res.fetchall()])
            self.assertEqual(results, {
                'scheduler_changes': [14],
                'change_files': [14],
                'change_properties': [],
                'changes': [14, 15],
            })
        yield self.db.pool.do(thd)
Exemplo n.º 2
0
    def test_multiple_source_stamps_no_props(self):
        repository = 'http://test_repo'
        project = 'test_user/test_project'
        codebase1 = 'test_codebase1'
        codebase2 = 'test_codebase2'
        codebase3 = 'test_codebase3'
        branch2 = 'refs/pull/4192/merge'
        branch3 = 'refs/pull/4193/merge'

        self._http.expect(
            'post',
            '/repos/test_user/test_project/issues/4192/comments',
            json={'body': 'Build done.'})
        self._http.expect(
            'post',
            '/repos/test_user/test_project/issues/4192/comments',
            json={'body': 'Build done.'})
        self._http.expect(
            'post',
            '/repos/test_user/test_project/issues/4192/comments',
            json={'body': 'Build done.'})
        self._http.expect(
            'post',
            '/repos/test_user/test_project/issues/4192/comments',
            json={'body': 'Build done.'})

        # note that the first sourcestamp only has revision, second only branch and only the third
        # has both
        self.master.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Buildset(id=98, results=SUCCESS, reason="test_reason1"),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=235),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=236),
            fakedb.SourceStamp(id=234, project=project, branch=None, revision='rev1',
                               repository=repository, codebase=codebase1),
            fakedb.SourceStamp(id=235, project=project, branch=branch2, revision=None,
                               repository=repository, codebase=codebase2),
            fakedb.SourceStamp(id=236, project=project, branch=branch3, revision='rev3',
                               repository=repository, codebase=codebase3),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=79),
            fakedb.Build(id=20, number=0, builderid=79, buildrequestid=11,
                         workerid=13, masterid=92, results=SUCCESS, state_string="build_text"),
            fakedb.BuildProperty(buildid=20, name="buildername", value="Builder0"),
            fakedb.BuildProperty(buildid=20, name="branch", value=branch2),
        ])

        self.setup_fake_get_changes_for_build(has_change=False)

        build = yield self.master.data.get(("builds", 20))

        build['complete'] = False
        yield self.sp._got_event(('builds', 20, 'new'), build)
        build['complete'] = True
        yield self.sp._got_event(('builds', 20, 'finished'), build)
        build['results'] = SUCCESS
        yield self.sp._got_event(('builds', 20, 'finished'), build)
Exemplo n.º 3
0
    def test_fromBrdict_multiple_sourcestamps(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='9283',
                               repository='svn://a..',
                               codebase='A',
                               project='world-domination'),
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://a..',
                          codebase='A',
                          project='world-domination',
                          sourcestampid=234),
            fakedb.SourceStamp(id=235,
                               branch='trunk',
                               revision='9284',
                               repository='svn://b..',
                               codebase='B',
                               project='world-domination'),
            fakedb.Change(changeid=14,
                          branch='trunk',
                          revision='9284',
                          repository='svn://b..',
                          codebase='B',
                          project='world-domination',
                          sourcestampid=235),
            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
        brdict = yield master.db.buildrequests.getBuildRequest(288)
        br = yield buildrequest.BuildRequest.fromBrdict(master, brdict)

        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)
Exemplo n.º 4
0
    def test_canBeCollapsed_different_codebases_raises_error(self):
        """ This testcase has two buildrequests
            Request Change Codebase   Revision Comment
            ----------------------------------------------------------------------
            288     17     C          1800     request 1 has repo not in request 2
            289     18     D          2100     request 2 has repo not in request 1
            --------------------------------
            Merge cannot be performed and raises error:
              Merging requests requires both requests to have the same codebases
        """
        brDicts = []  # list of buildrequests dictionary
        master = fakemaster.make_master(self, wantData=True, wantDb=True)
        master.db.insertTestData([
            fakedb.Builder(id=77, name='bldr'),
            fakedb.SourceStamp(id=238,
                               branch='trunk',
                               revision='1800',
                               repository='svn://c..',
                               codebase='C',
                               project='world-domination'),
            fakedb.Change(changeid=17,
                          branch='trunk',
                          revision='1800',
                          repository='svn://c..',
                          codebase='C',
                          project='world-domination',
                          sourcestampid=238),
            fakedb.SourceStamp(id=239,
                               branch='trunk',
                               revision='2100',
                               repository='svn://d..',
                               codebase='D',
                               project='world-domination'),
            fakedb.Change(changeid=18,
                          branch='trunk',
                          revision='2100',
                          repository='svn://d..',
                          codebase='D',
                          project='world-domination',
                          sourcestampid=239),
            fakedb.Buildset(id=539, reason='triggered'),
            fakedb.BuildsetSourceStamp(buildsetid=539, sourcestampid=238),
            fakedb.BuildRequest(id=288, buildsetid=539, builderid=77),
            fakedb.Buildset(id=540, reason='triggered'),
            fakedb.BuildsetSourceStamp(buildsetid=540, sourcestampid=239),
            fakedb.BuildRequest(id=289, buildsetid=540, builderid=77),
        ])
        # use getBuildRequest to minimize the risk from changes to the format
        # of the brdict
        req = yield master.db.buildrequests.getBuildRequest(288)
        brDicts.append(req)
        req = yield master.db.buildrequests.getBuildRequest(289)
        brDicts.append(req)
        can_collapse = \
            yield buildrequest.BuildRequest.canBeCollapsed(master, brDicts[0],
                                                           brDicts[1])

        self.assertEqual(can_collapse, False)
Exemplo n.º 5
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Buildset(id=13, reason='because I said so'),
         fakedb.SourceStamp(id=92),
         fakedb.SourceStamp(id=93),
         fakedb.BuildsetSourceStamp(buildsetid=13, sourcestampid=92),
         fakedb.BuildsetSourceStamp(buildsetid=13, sourcestampid=93),
         fakedb.Buildset(id=14, reason='no sourcestamps'),
     ])
Exemplo n.º 6
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.SourceStamp(id=13, branch='oak'),
         fakedb.Patch(id=99,
                      patch_base64='aGVsbG8sIHdvcmxk',
                      patch_author='bar',
                      patch_comment='foo',
                      subdir='/foo',
                      patchlevel=3),
         fakedb.SourceStamp(id=14, patchid=99, branch='poplar'),
     ])
Exemplo n.º 7
0
    def setupDb(self):
        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Buildset(id=98, results=SUCCESS, reason="testReason1"),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.BuildRequest(id=9, buildsetid=97, builderid=80),
            fakedb.BuildRequest(id=10, buildsetid=97, builderid=80),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=80),
            fakedb.BuildRequest(id=12, buildsetid=98, builderid=80),
            fakedb.Build(id=18, number=0, builderid=80, buildrequestid=9, workerid=13,
                         masterid=92, results=FAILURE),
            fakedb.Build(id=19, number=1, builderid=80, buildrequestid=10, workerid=13,
                         masterid=92, results=RETRY),
            fakedb.Build(id=20, number=2, builderid=80, buildrequestid=11, workerid=13,
                         masterid=92, results=SUCCESS),
            fakedb.Build(id=21, number=3, builderid=80, buildrequestid=12, workerid=13,
                         masterid=92, results=SUCCESS),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234),
            fakedb.Change(changeid=13, branch='trunk', revision='9283', author='me@foo',
                          repository='svn://...', codebase='cbsvn',
                          project='world-domination', sourcestampid=234),
            fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk',
                         patch_author='him@foo', patch_comment='foo', subdir='/foo',
                         patchlevel=3),
            fakedb.SourceStamp(id=235, patchid=99),
        ])
        for _id in (20, 21):
            self.db.insertTestData([
                fakedb.BuildProperty(
                    buildid=_id, name="workername", value="wrk"),
                fakedb.BuildProperty(
                    buildid=_id, name="reason", value="because"),
                fakedb.BuildProperty(
                    buildid=_id, name="owner", value="him"),
                fakedb.Step(id=100 + _id, buildid=_id, name="step1"),
                fakedb.Step(id=200 + _id, buildid=_id, name="step2"),
                fakedb.Log(id=60 + _id, stepid=100 + _id, name='stdio', slug='stdio', type='s',
                           num_lines=2),
                fakedb.LogChunk(logid=60 + _id, first_line=0, last_line=1, compressed=0,
                                content=self.LOGCONTENT),
            ])

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

        self.master.db.changes.getChangesForBuild = getChangesForBuild
Exemplo n.º 8
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.SourceStamp(id=133),
         fakedb.Change(changeid=13, branch='trunk', revision='9283',
                       repository='svn://...', codebase='cbsvn',
                       project='world-domination', sourcestampid=133),
         fakedb.SourceStamp(id=144),
         fakedb.Change(changeid=14, branch='devel', revision='9284',
                       repository='svn://...', codebase='cbsvn',
                       project='world-domination', sourcestampid=144),
         fakedb.Build(buildrequestid=1, masterid=1, workerid=1, builderid=1),
     ])
Exemplo n.º 9
0
    def test_getChangesHugeCount(self):
        yield self.insertTestData([
            fakedb.SourceStamp(id=92),
        ] + [fakedb.Change(changeid=i) for i in range(2, 102)])
        n = yield self.db.changes.getChangesCount()

        self.assertEqual(n, 100)
Exemplo n.º 10
0
    def insert_buildrequest_new(self, insert_patch=False, **kwargs):
        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.Buildset(id=98, results=None, reason="testReason1",
                            parent_buildid=None),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=79)
        ])

        patchid = 99 if insert_patch else None

        self.db.insertTestData([
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(
                id=234,
                branch=self.reporter_test_branch,
                project=self.reporter_test_project,
                revision=self.reporter_test_revision,
                repository=self.reporter_test_repo,
                codebase=self.reporter_test_codebase,
                patchid=patchid),
            fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk',
                         patch_author='him@foo', patch_comment='foo', subdir='/foo',
                         patchlevel=3)
        ])
        request = yield self.master.data.get(("buildrequests", 11))
        return request
Exemplo n.º 11
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)
Exemplo n.º 12
0
    def test_source_stamp_no_props_nightly_scheduler(self):
        # no status updates are expected

        self.master.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Buildset(id=98, results=SUCCESS, reason="test_reason1"),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234, project=None, branch=None, revision=None,
                               repository=None, codebase=None),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=79),
            fakedb.Build(id=20, number=0, builderid=79, buildrequestid=11,
                         workerid=13, masterid=92, results=SUCCESS, state_string="build_text"),
            fakedb.BuildProperty(buildid=20, name="workername", value="wrk"),
            fakedb.BuildProperty(buildid=20, name="reason", value="because"),
            fakedb.BuildProperty(buildid=20, name="buildername", value="Builder0"),
            fakedb.BuildProperty(buildid=20, name="branch", value=None),
            fakedb.BuildProperty(buildid=20, name="codebase", value=""),
            fakedb.BuildProperty(buildid=20, name="project", value=""),
            fakedb.BuildProperty(buildid=20, name="repository", value=""),
            fakedb.BuildProperty(buildid=20, name="revision", value=None),
        ])

        self.setup_fake_get_changes_for_build(has_change=False)

        build = yield self.master.data.get(("builds", 20))

        build['complete'] = False
        yield self.sp._got_event(('builds', 20, 'new'), build)
        build['complete'] = True
        yield self.sp._got_event(('builds', 20, 'finished'), build)
        build['results'] = SUCCESS
        yield self.sp._got_event(('builds', 20, 'finished'), build)
Exemplo n.º 13
0
    def makeBuildRequestRows(self, brid, bsid, changeid, ssid, codebase, branch=None,
                             project=None, repository=None, patchid=None, revision=None):
        rows = [
            fakedb.SourceStamp(id=ssid, codebase=codebase, branch=branch,
                               project=project, repository=repository, patchid=patchid,
                               revision=revision),
            fakedb.Buildset(id=bsid, reason='foo',
                            submitted_at=1300305712, results=-1),
            fakedb.BuildsetSourceStamp(sourcestampid=ssid, buildsetid=bsid),
            fakedb.BuildRequest(id=brid, buildsetid=bsid, builderid=77,
                            priority=13, submitted_at=1300305712, results=-1),
            ]
        if changeid:
            rows.append(
                fakedb.Change(changeid=changeid, branch='trunk', revision='9283',
                              repository='svn://...', project='world-domination',
                              sourcestampid=ssid)
                              )
        if patchid:
            rows.append(
                fakedb.Patch(id=patchid, patch_base64='aGVsbG8sIHdvcmxk',
                 patch_author='bar', patch_comment='foo', subdir='/foo',
                 patchlevel=3))

        return rows
Exemplo n.º 14
0
    def test_addBuildsetForSourceStamp_combine_change_properties(self):
        sched = self.makeScheduler()

        self.master.db.insertTestData([
            fakedb.SourceStamp(id=98, branch='stable'),
            fakedb.Change(changeid=25, sourcestampid=98, branch='stable'),
            fakedb.ChangeProperty(changeid=25,
                                  property_name='color',
                                  property_value='["pink","Change"]'),
        ])

        bsid, brids = yield sched.addBuildsetForSourceStamps(reason='whynot',
                                                             waited_for=False,
                                                             sourcestamps=[98])
        self.assertEqual((bsid, brids), self.exp_bsid_brids)
        self.master.data.updates.addBuildset.assert_called_with(
            waited_for=False,
            builderids=[1, 2],
            external_idstring=None,
            properties={
                'scheduler': ('testsched', 'Scheduler'),
                'color': ('pink', 'Change')
            },
            reason='whynot',
            scheduler='testsched',
            sourcestamps=[98])
Exemplo n.º 15
0
    def test_getSourceStampsForBuild_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, codebase='A', 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),
                fakedb.Build(id=50, buildrequestid=19, number=5, masterid=88,
                             builderid=77, state_string="test", workerid=13,
                             started_at=1304262222), ]

        expected = [{
            'branch': 'master',
            'codebase': 'A',
            'created_at': epoch2datetime(CREATED_AT),
            'patch_author': None,
            'patch_body': None,
            'patch_comment': None,
            'patch_level': None,
            'patch_subdir': None,
            'patchid': None,
            'project': 'proj',
            'repository': 'repo',
            'revision': 'aaa',
            'ssid': 234}]

        return self.do_test_getSourceStampsForBuild(rows, 50, expected)
    def setUp(self):
        self.setUpTestReactor()
        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(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()

        # 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),
        ]
Exemplo n.º 17
0
    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'),
        ])
Exemplo n.º 18
0
    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)
Exemplo n.º 19
0
    def test_pruneChanges_lots(self):
        yield self.insertTestData([
            fakedb.SourceStamp(id=29),
        ] + [
            fakedb.Change(changeid=n, sourcestampid=29)
            for n in range(1, 151)
        ])

        yield self.db.changes.pruneChanges(1)

        def thd(conn):
            results = {}
            for tbl_name in ('scheduler_changes', 'change_files',
                             'change_properties', 'changes'):
                tbl = self.db.model.metadata.tables[tbl_name]
                res = conn.execute(sa.select([sa.func.count()]).select_from(tbl))
                results[tbl_name] = res.fetchone()[0]
                res.close()
            self.assertEqual(results, {
                'scheduler_changes': 0,
                'change_files': 0,
                'change_properties': 0,
                'changes': 1,
            })
        yield self.db.pool.do(thd)
Exemplo n.º 20
0
        def addChange(codebase, revision, author, committer, comments, branch='master',
                      category='cat', project='proj', repository='repo'):
            lastID["sourcestampid"] += 1
            lastID["changeid"] += 1
            parent_changeids = codebase_ss.get(codebase, None)

            codebase_ss[codebase] = lastID["sourcestampid"]

            changeRows = [fakedb.SourceStamp(id=lastID["sourcestampid"],
                                             codebase=codebase,
                                             revision=revision),
                          fakedb.Change(changeid=lastID["changeid"],
                                        author=author,
                                        committer=committer,
                                        comments=comments,
                                        revision=revision,
                                        sourcestampid=lastID["sourcestampid"],
                                        parent_changeids=parent_changeids,
                                        when_timestamp=SOMETIME +
                                        lastID["changeid"],
                                        branch=branch,
                                        category=category,
                                        project=project,
                                        repository=repository)]
            return changeRows
Exemplo n.º 21
0
    def test_addBuildsetForSourceStamp_list_of_renderable_builderNames(self):
        names = ['a', 'b', properties.Interpolate('%(prop:extra_builder)s')]
        sched = self.makeScheduler(name='n', builderNames=names)

        self.master.db.insertTestData([
            fakedb.Builder(id=1, name='a'),
            fakedb.Builder(id=2, name='b'),
            fakedb.Builder(id=3, name='c'),
            fakedb.SourceStamp(id=98, branch='stable'),
            fakedb.Change(changeid=25, sourcestampid=98, branch='stable'),
            fakedb.ChangeProperty(changeid=25,
                                  property_name='extra_builder',
                                  property_value='["c","Change"]'),
        ])

        bsid, brids = yield sched.addBuildsetForSourceStamps(reason='whynot',
                                                             waited_for=False,
                                                             sourcestamps=[98])
        self.assertEqual((bsid, brids), self.exp_bsid_brids)
        self.master.data.updates.addBuildset.assert_called_with(
            waited_for=False,
            builderids=[1, 2, 3],
            external_idstring=None,
            properties={
                'scheduler': ('n', 'Scheduler'),
                'extra_builder': ('c', 'Change')
            },
            reason='whynot',
            scheduler='n',
            sourcestamps=[98])
Exemplo n.º 22
0
 def test_addBuildsetForChanges_properties_with_virtual_builders(self):
     sched = self.makeScheduler(name='n',
                                builderNames=['c'],
                                properties={
                                    'virtual_builder_name':
                                    Interpolate("myproject-%(src::branch)s")
                                })
     self.db.insertTestData([
         fakedb.SourceStamp(id=234, branch='dev1', project="linux"),
         fakedb.Change(changeid=14, sourcestampid=234, branch="dev1"),
     ])
     bsid, brids = yield sched.addBuildsetForChanges(reason='downstream',
                                                     waited_for=False,
                                                     changeids=[14])
     self.assertEqual((bsid, brids), self.exp_bsid_brids)
     self.master.data.updates.addBuildset.assert_called_with(
         waited_for=False,
         builderids=[1],
         external_idstring=None,
         properties={
             'virtual_builder_name': ("myproject-dev1", "Scheduler"),
             'scheduler': ('n', 'Scheduler'),
         },
         reason='downstream',
         scheduler='n',
         sourcestamps=[234])
Exemplo n.º 23
0
    def test_addBuildsetForSourceStamp_renderable_builderNames(self):
        @properties.renderer
        def names(props):
            if props.changes[0]['branch'] == 'stable':
                return ['c']
            elif props.changes[0]['branch'] == 'unstable':
                return ['a', 'b']

        sched = self.makeScheduler(name='n', builderNames=names)

        self.master.db.insertTestData([
            fakedb.Builder(id=1, name='a'),
            fakedb.Builder(id=2, name='b'),
            fakedb.Builder(id=3, name='c'),
            fakedb.SourceStamp(id=98, branch='stable'),
            fakedb.SourceStamp(id=99, branch='unstable'),
            fakedb.Change(changeid=25, sourcestampid=98, branch='stable'),
            fakedb.Change(changeid=26, sourcestampid=99, branch='unstable'),
        ])

        bsid, brids = yield sched.addBuildsetForSourceStamps(reason='whynot',
                                                             waited_for=False,
                                                             sourcestamps=[98])
        self.assertEqual((bsid, brids), self.exp_bsid_brids)
        self.master.data.updates.addBuildset.assert_called_with(
            waited_for=False,
            builderids=[3],
            external_idstring=None,
            properties={
                'scheduler': ('n', 'Scheduler')},
            reason='whynot',
            scheduler='n',
            sourcestamps=[98])

        bsid, brids = yield sched.addBuildsetForSourceStamps(reason='because',
                                                             waited_for=False,
                                                             sourcestamps=[99])
        self.assertEqual((bsid, brids), self.exp_bsid_brids)
        self.master.data.updates.addBuildset.assert_called_with(
            waited_for=False,
            builderids=[1, 2],
            external_idstring=None,
            properties={
                'scheduler': ('n', 'Scheduler')},
            reason='because',
            scheduler='n',
            sourcestamps=[99])
Exemplo n.º 24
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.SourceStamp(id=234),
         fakedb.Change(changeid=13, branch='trunk', revision='9283',
                       repository='svn://...', codebase='cbsvn',
                       project='world-domination', sourcestampid=234),
     ])
Exemplo n.º 25
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.SourceStamp(id=92),
         fakedb.Buildset(id=13, complete=True),
         fakedb.Buildset(id=14, complete=False),
         fakedb.BuildsetSourceStamp(buildsetid=13, sourcestampid=92),
         fakedb.BuildsetSourceStamp(buildsetid=14, sourcestampid=92),
     ])
Exemplo n.º 26
0
 def setUp(self):
     self.setup_test_reactor()
     # a collection of rows that would otherwise clutter up every test
     self.setUpBuilderMixin()
     self.base_rows = [
         fakedb.SourceStamp(id=21),
         fakedb.Buildset(id=11, reason='because'),
         fakedb.BuildsetSourceStamp(buildsetid=11, sourcestampid=21),
     ]
Exemplo n.º 27
0
 def insert7Changes(self):
     return self.insertTestData([
         fakedb.SourceStamp(id=922),
         fakedb.Change(changeid=8, sourcestampid=922),
         fakedb.Change(changeid=9, sourcestampid=922),
         fakedb.Change(changeid=10, sourcestampid=922),
         fakedb.Change(changeid=11, sourcestampid=922),
         fakedb.Change(changeid=12, sourcestampid=922),
     ] + self.change13_rows + self.change14_rows)
Exemplo n.º 28
0
    def test_getChangeUids_found(self):
        yield self.insertTestData(self.change14_rows + [
            fakedb.SourceStamp(id=92),
            fakedb.User(uid=1),
            fakedb.ChangeUser(changeid=14, uid=1),
        ])
        res = yield self.db.changes.getChangeUids(14)

        self.assertEqual(res, [1])
Exemplo n.º 29
0
    def test_getSourceStamps(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, revision='r', project='p',
                               codebase='c', repository='rep', branch='b', patchid=99,
                               created_at=CREATED_AT),
            fakedb.SourceStamp(id=235, revision='r2', project='p2',
                               codebase='c2', repository='rep2', branch='b2', patchid=None,
                               created_at=CREATED_AT + 10),
        ])
        sourcestamps = yield self.db.sourcestamps.getSourceStamps()

        self.assertEqual(sorted(sourcestamps, key=sourceStampKey),
                         sorted([{
                                 'branch': 'b',
                                 'codebase': 'c',
                                 'patch_author': 'bar',
                                 'patchid': 99,
                                 'patch_body': b'hello, world',
                                 'patch_comment': 'foo',
                                 'patch_level': 3,
                                 'patch_subdir': '/foo',
                                 'project': 'p',
                                 'repository': 'rep',
                                 'revision': 'r',
                                 'created_at': epoch2datetime(CREATED_AT),
                                 'ssid': 234,
                                 }, {
                                 'branch': 'b2',
                                 'codebase': 'c2',
                                 'patchid': None,
                                 'patch_author': None,
                                 'patch_body': None,
                                 'patch_comment': None,
                                 'patch_level': None,
                                 'patch_subdir': None,
                                 'project': 'p2',
                                 'repository': 'rep2',
                                 'revision': 'r2',
                                 'created_at': epoch2datetime(CREATED_AT + 10),
                                 'ssid': 235,
                                 }], key=sourceStampKey))
Exemplo n.º 30
0
    def do_test(self, scheduler_name, expect_subscription,
                results, expect_buildset):
        """Test the dependent scheduler by faking a buildset and subsequent
        completion from an upstream scheduler.

        @param scheduler_name: upstream scheduler's name
        @param expect_subscription: whether to expect the dependent to
            subscribe to the buildset
        @param results: results of the upstream scheduler's buildset
        @param expect_buidlset: whether to expect the dependent to generate
            a new buildset in response
        """

        sched = self.makeScheduler()
        sched.activate()

        # announce a buildset with a matching name..
        self.db.insertTestData([
            fakedb.SourceStamp(id=93, revision='555',
                               branch='master', project='proj', repository='repo',
                               codebase='cb'),
            fakedb.Buildset(
                id=44,
                submitted_at=SUBMITTED_AT_TIME,
                complete=False,
                complete_at=None,
                external_idstring=None,
                reason='Because',
                results=-1,
            ),
            fakedb.BuildsetSourceStamp(buildsetid=44, sourcestampid=93),
        ])
        self.sendBuildsetMessage(scheduler_name=scheduler_name, complete=False)

        # 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=results)
        self.sendBuildsetMessage(results=results, complete=True)

        # and check whether a buildset was added in response
        if expect_buildset:
            self.assertEqual(self.addBuildsetCalls, [
                ('addBuildsetForSourceStamps', dict(
                    builderNames=None,  # defaults
                    external_idstring=None,
                    properties=None,
                    reason='downstream',
                    sourcestamps=[93])),
            ])
        else:
            self.assertEqual(self.addBuildsetCalls, [])