示例#1
0
    def test_fromSsdict_changes(self):
        master = fakemaster.make_master()
        master.db = fakedb.FakeDBConnector(self)
        master.db.insertTestData([
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://...',
                          codebase='cb',
                          project='world-domination'),
            fakedb.Change(changeid=14,
                          branch='trunk',
                          revision='9284',
                          repository='svn://...',
                          codebase='cb',
                          project='world-domination'),
            fakedb.Change(changeid=15,
                          branch='trunk',
                          revision='9284',
                          repository='svn://...',
                          codebase='cb',
                          project='world-domination'),
            fakedb.Change(changeid=16,
                          branch='trunk',
                          revision='9284',
                          repository='svn://...',
                          codebase='cb',
                          project='world-domination'),
            fakedb.SourceStamp(id=234,
                               branch='trunk',
                               revision='9284',
                               repository='svn://...',
                               codebase='cb',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=234, changeid=14),
            fakedb.SourceStampChange(sourcestampid=234, changeid=13),
            fakedb.SourceStampChange(sourcestampid=234, changeid=15),
            fakedb.SourceStampChange(sourcestampid=234, changeid=16),
        ])
        # 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(ss.patch_info, None)
            self.assertEqual([ch.number for ch in ss.changes],
                             [13, 14, 15, 16])
            self.assertEqual(ss.project, 'world-domination')
            self.assertEqual(ss.repository, 'svn://...')
            self.assertEqual(ss.codebase, 'cb')

        d.addCallback(check)
        return d
示例#2
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]
                    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],
                    'sourcestamp_changes': [15],
                    'change_files': [14],
                    'change_properties': [],
                    'changes': [14, 15],
                })
            return self.db.pool.do(thd)
        d.addCallback(check)
        return d
    def insert_test_getRecentBuildsets_data(self):
        return self.insertTestData([
            fakedb.Change(changeid=91, branch='branch_a', repository='repo_a'),
            fakedb.SourceStamp(id=91, branch='branch_a', repository='repo_a'),
            fakedb.SourceStampChange(sourcestampid=91, changeid=91),
            fakedb.Buildset(id=91,
                            sourcestampid=91,
                            complete=0,
                            complete_at=298297875,
                            results=-1,
                            submitted_at=266761875,
                            external_idstring='extid',
                            reason='rsn1'),
            fakedb.Buildset(id=92,
                            sourcestampid=91,
                            complete=1,
                            complete_at=298297876,
                            results=7,
                            submitted_at=266761876,
                            external_idstring='extid',
                            reason='rsn2'),

            # buildset unrelated to the change
            fakedb.Buildset(id=93,
                            sourcestampid=1,
                            complete=1,
                            complete_at=298297877,
                            results=7,
                            submitted_at=266761877,
                            external_idstring='extid',
                            reason='rsn2'),
        ])
示例#4
0
    def test_mergeRequest_no_other_request(self):
        """ Test if builder test for codebases in requests """
        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, codebase='A'),
            fakedb.Change(changeid=14, codebase='A'),
            fakedb.SourceStampChange(sourcestampid=234, changeid=14),
            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),
        ])

        brdicts = yield defer.gatherResults(
            [self.db.buildrequests.getBuildRequest(19)])

        def mergeRequests_fn(builder, breq, other):
            # Allow all requests
            return True

        # check if the request remains the same
        res = yield self.bldr._mergeRequests(brdicts[0], brdicts,
                                             mergeRequests_fn)
        self.assertEqual(res, [brdicts[0]])
 def test_getSourceStamp_changes(self):
     d = self.insertTestData([
         fakedb.Change(changeid=16),
         fakedb.Change(changeid=19),
         fakedb.Change(changeid=20),
         fakedb.SourceStampSet(id=234),
         fakedb.SourceStamp(id=234, sourcestampsetid=234),
         fakedb.SourceStampChange(sourcestampid=234, changeid=16),
         fakedb.SourceStampChange(sourcestampid=234, changeid=20),
     ])
     d.addCallback(lambda _ :
             self.db.sourcestamps.getSourceStamp(234))
     def check(ssdict):
         self.assertEqual(ssdict['changeids'], set([16,20]))
     d.addCallback(check)
     return d
    def test_mergeRequest_no_other_request(self):
        """ Test if builder test for codebases in requests """
        # set up all of the data required for a BuildRequest object
        rows = [
            fakedb.SourceStampSet(id=234),
            fakedb.SourceStamp(id=234, sourcestampsetid=234, codebase='A'),
            fakedb.Change(changeid=14, codebase='A'),
            fakedb.SourceStampChange(sourcestampid=234, changeid=14),
            fakedb.Buildset(id=30, sourcestampsetid=234, reason='foo',
                            submitted_at=1300305712, results=-1),
            fakedb.BuildRequest(id=19, buildsetid=30, buildername='A',
                                priority=13, submitted_at=1300305712, results=-1),
        ]

        self.addSlaves({'test-slave1': 1, 'test-slave2': 1})

        def mergeRequests_fn(builder, breq, other):
            # Allow all requests
            self.fail("Should never be called")
            return True
        self.bldr.getMergeRequestsFn = lambda: mergeRequests_fn

        # check if the request remains the same
        yield self.do_test_maybeStartBuildsOnBuilder(rows=rows,
                                                     exp_claims=[19],
                                                     exp_builds=[
                                                         ('test-slave1', [19]),
                                                     ])
    def test_fromBrdict(self):
        master = fakemaster.make_master()
        master.db = fakedb.FakeDBConnector(self)
        master.db.insertTestData([
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://...',
                          project='world-domination'),
            fakedb.SourceStampSet(id=234),
            fakedb.SourceStamp(id=234,
                               sourcestampsetid=234,
                               branch='trunk',
                               revision='9284',
                               repository='svn://...',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=234, changeid=13),
            fakedb.Buildset(id=539, reason='triggered', sourcestampsetid=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,
                                buildername='bldr',
                                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(br.source.ssid, 234)
            self.assertEqual([ch.number for ch in br.source.changes], [13])

            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
    def test_canBeMergedWith_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 performd and raises error:
              Merging requests requires both requests to have the same codebases
        """
        brs = []  # list of buildrequests
        master = fakemaster.make_master()
        master.db = fakedb.FakeDBConnector(self)
        master.db.insertTestData([
            fakedb.SourceStampSet(id=2340),
            fakedb.Change(changeid=17,
                          branch='trunk',
                          revision='1800',
                          repository='svn://c..',
                          codebase='C',
                          project='world-domination'),
            fakedb.SourceStamp(id=238,
                               sourcestampsetid=2340,
                               branch='trunk',
                               revision='1800',
                               repository='svn://c..',
                               codebase='C',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=238, changeid=17),
            fakedb.SourceStampSet(id=2360),
            fakedb.Change(changeid=18,
                          branch='trunk',
                          revision='2100',
                          repository='svn://d..',
                          codebase='D',
                          project='world-domination'),
            fakedb.SourceStamp(id=239,
                               sourcestampsetid=2360,
                               branch='trunk',
                               revision='2100',
                               repository='svn://d..',
                               codebase='D',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=239, changeid=18),
            fakedb.Buildset(id=539, reason='triggered', sourcestampsetid=2340),
            fakedb.BuildRequest(id=288, buildsetid=539, buildername='bldr'),
            fakedb.Buildset(id=540, reason='triggered', sourcestampsetid=2360),
            fakedb.BuildRequest(id=289, buildsetid=540, buildername='bldr'),
        ])
        # 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))
        d.addCallback(lambda br: brs.append(br))
        d.addCallback(lambda _: master.db.buildrequests.getBuildRequest(289))
        d.addCallback(lambda brdict: buildrequest.BuildRequest.fromBrdict(
            master, brdict))
        d.addCallback(lambda br: brs.append(br))

        def check(_):
            self.assertEqual(brs[0].canBeMergedWith(brs[1]), False)

        d.addCallback(check)
        return d
    def test_mergeSourceStampsWith_common_codebases(self):
        """ This testcase has two buildrequests
            Request Change Codebase Revision Comment
            ----------------------------------------------------------------------
            288     13     A        9283
            289     15     A        9284
            288     14     B        9200
            289     16     B        9201
            -------------------------------- 
            After merged in Build:
            Source1 has rev 9284 and contains changes 13 and 15 from repository svn://a
            Source2 has rev 9201 and contains changes 14 and 16 from repository svn://b
        """
        brs = []  # list of buildrequests
        master = fakemaster.make_master()
        master.db = fakedb.FakeDBConnector(self)
        master.db.insertTestData([
            fakedb.SourceStampSet(id=2340),
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://a..',
                          codebase='A',
                          project='world-domination'),
            fakedb.SourceStamp(id=234,
                               sourcestampsetid=2340,
                               branch='trunk',
                               revision='9283',
                               repository='svn://a..',
                               codebase='A',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=234, changeid=13),
            fakedb.Change(changeid=14,
                          branch='trunk',
                          revision='9200',
                          repository='svn://b..',
                          codebase='A',
                          project='world-domination'),
            fakedb.SourceStamp(id=235,
                               sourcestampsetid=2340,
                               branch='trunk',
                               revision='9200',
                               repository='svn://b..',
                               codebase='B',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=235, changeid=14),
            fakedb.SourceStampSet(id=2360),
            fakedb.Change(changeid=15,
                          branch='trunk',
                          revision='9284',
                          repository='svn://a..',
                          codebase='A',
                          project='world-domination'),
            fakedb.SourceStamp(id=236,
                               sourcestampsetid=2360,
                               branch='trunk',
                               revision='9284',
                               repository='svn://a..',
                               codebase='A',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=236, changeid=15),
            fakedb.Change(changeid=16,
                          branch='trunk',
                          revision='9201',
                          repository='svn://b..',
                          codebase='B',
                          project='world-domination'),
            fakedb.SourceStamp(id=237,
                               sourcestampsetid=2360,
                               branch='trunk',
                               revision='9201',
                               repository='svn://b..',
                               codebase='B',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=237, changeid=16),
            fakedb.Buildset(id=539, reason='triggered', sourcestampsetid=2340),
            fakedb.BuildRequest(id=288, buildsetid=539, buildername='bldr'),
            fakedb.Buildset(id=540, reason='triggered', sourcestampsetid=2360),
            fakedb.BuildRequest(id=289, buildsetid=540, buildername='bldr'),
        ])
        # 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))
        d.addCallback(lambda br: brs.append(br))
        d.addCallback(lambda _: master.db.buildrequests.getBuildRequest(289))
        d.addCallback(lambda brdict: buildrequest.BuildRequest.fromBrdict(
            master, brdict))
        d.addCallback(lambda br: brs.append(br))

        def check(_):
            sources = brs[0].mergeSourceStampsWith(brs[1:])

            source1 = source2 = None
            for source in sources:
                if source.codebase == 'A':
                    source1 = source
                if source.codebase == 'B':
                    source2 = source

            self.assertFalse(source1 == None)
            self.assertEqual(source1.revision, '9284')

            self.assertFalse(source2 == None)
            self.assertEqual(source2.revision, '9201')

            self.assertEqual([c.number for c in source1.changes], [13, 15])
            self.assertEqual([c.number for c in source2.changes], [14, 16])

        d.addCallback(check)
        return d