def insert_test_getRecentBuildsets_data(self): return self.insertTestData([ fakedb.SourceStamp(id=91, branch='branch_a', repository='repo_a', sourcestampsetid=91), fakedb.SourceStampSet(id=91), fakedb.Buildset(id=91, sourcestampsetid=91, complete=0, complete_at=298297875, results=-1, submitted_at=266761875, external_idstring='extid', reason='rsn1'), fakedb.Buildset(id=92, sourcestampsetid=91, complete=1, complete_at=298297876, results=7, submitted_at=266761876, external_idstring='extid', reason='rsn2'), # buildset unrelated to the change fakedb.SourceStampSet(id=1), fakedb.Buildset(id=93, sourcestampsetid=1, complete=1, complete_at=298297877, results=7, submitted_at=266761877, external_idstring='extid', reason='rsn2'), ])
def test_merge_ordering(self): # (patch_random=True) self.bldr.getMergeRequestsFn = lambda: lambda _, req1, req2: req1.canBeMergedWith(req2) self.addSlaves({'test-slave1': 1}) # based on the build in bug #2249 rows = [ fakedb.SourceStampSet(id=1976), fakedb.SourceStamp(id=1976, sourcestampsetid=1976), fakedb.Buildset(id=1980, reason='scheduler', sourcestampsetid=1976, submitted_at=1332024020.67792), fakedb.BuildRequest(id=42880, buildsetid=1980, submitted_at=1332024020.67792, buildername="A"), fakedb.SourceStampSet(id=1977), fakedb.SourceStamp(id=1977, sourcestampsetid=1977), fakedb.Buildset(id=1981, reason='scheduler', sourcestampsetid=1977, submitted_at=1332025495.19141), fakedb.BuildRequest(id=42922, buildsetid=1981, buildername="A", submitted_at=1332025495.19141), ] yield self.do_test_maybeStartBuildsOnBuilder(rows=rows, exp_claims=[42880, 42922], exp_builds=[('test-slave1', [42880, 42922])])
def do_test_getBuildRequests_branch_arg(self, **kwargs): expected = kwargs.pop('expected') d = self.insertTestData([ fakedb.BuildRequest(id=70, buildsetid=self.BSID + 1), fakedb.Buildset(id=self.BSID + 1, sourcestampsetid=self.BSID + 1), fakedb.SourceStampSet(id=self.BSID + 1), fakedb.SourceStamp(sourcestampsetid=self.BSID + 1, branch='branch_A'), fakedb.BuildRequest(id=80, buildsetid=self.BSID + 2), fakedb.Buildset(id=self.BSID + 2, sourcestampsetid=self.BSID + 2), fakedb.SourceStampSet(id=self.BSID + 2), fakedb.SourceStamp(sourcestampsetid=self.BSID + 2, repository='repository_A'), fakedb.BuildRequest(id=90, buildsetid=self.BSID + 3), fakedb.Buildset(id=self.BSID + 3, sourcestampsetid=self.BSID + 3), fakedb.SourceStampSet(id=self.BSID + 3), fakedb.SourceStamp(sourcestampsetid=self.BSID + 3, branch='branch_A', repository='repository_A'), ]) d.addCallback( lambda _: self.db.buildrequests.getBuildRequests(**kwargs)) def check(brlist): self.assertEqual(sorted([br['brid'] for br in brlist]), sorted(expected)) d.addCallback(check) return d
def test_mergeRequests_no_merging(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='C'), fakedb.Buildset(id=30, sourcestampsetid=234, reason='foo', submitted_at=1300305712, results=-1), fakedb.SourceStampSet(id=235), fakedb.SourceStamp(id=235, sourcestampsetid=235, codebase='C'), fakedb.Buildset(id=31, sourcestampsetid=235, reason='foo', submitted_at=1300305712, results=-1), fakedb.SourceStampSet(id=236), fakedb.SourceStamp(id=236, sourcestampsetid=236, codebase='C'), fakedb.Buildset(id=32, sourcestampsetid=236, reason='foo', submitted_at=1300305712, results=-1), fakedb.BuildRequest(id=19, buildsetid=30, buildername='A', priority=13, submitted_at=1300305712, results=-1), fakedb.BuildRequest(id=20, buildsetid=31, buildername='A', priority=13, submitted_at=1300305712, results=-1), fakedb.BuildRequest(id=21, buildsetid=32, buildername='A', priority=13, submitted_at=1300305712, results=-1), ] self.addSlaves({'test-slave1': 1, 'test-slave2': 1}) def mergeRequests_fn(builder, breq, other): # Fail all merge attempts return False self.bldr.getMergeRequestsFn = lambda: mergeRequests_fn # check if all are merged yield self.do_test_maybeStartBuildsOnBuilder(rows=rows, exp_claims=[19, 20], exp_builds=[ ('test-slave1', [19]), ('test-slave2', [20]), ])
def test_maybeStartBuild_merge_ordering(self): yield self.makeBuilder(patch_random=True) self.setSlaveBuilders({'bldr': 1}) # based on the build in bug #2249 rows = [ fakedb.SourceStampSet(id=1976), fakedb.SourceStamp(id=1976, sourcestampsetid=1976), fakedb.Buildset(id=1980, reason='scheduler', sourcestampsetid=1976, submitted_at=1332024020.67792), fakedb.BuildRequest(id=42880, buildsetid=1980, submitted_at=1332024020.67792, buildername="bldr"), fakedb.SourceStampSet(id=1977), fakedb.SourceStamp(id=1977, sourcestampsetid=1977), fakedb.Buildset(id=1981, reason='scheduler', sourcestampsetid=1977, submitted_at=1332025495.19141), fakedb.BuildRequest(id=42922, buildsetid=1981, buildername="bldr", submitted_at=1332025495.19141), ] yield self.do_test_maybeStartBuild(rows=rows, exp_claims=[42880, 42922], exp_builds=[('bldr', [42880, 42922])])
def test_mergeRequests_codebases_equal(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.Buildset(id=30, sourcestampsetid=234, reason='foo', submitted_at=1300305712, results=-1), fakedb.SourceStampSet(id=235), fakedb.SourceStamp(id=235, sourcestampsetid=235, codebase='A'), fakedb.Buildset(id=31, sourcestampsetid=235, reason='foo', submitted_at=1300305712, results=-1), fakedb.SourceStampSet(id=236), fakedb.SourceStamp(id=236, sourcestampsetid=236, codebase='A'), fakedb.Buildset(id=32, sourcestampsetid=236, 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=31, buildername='bldr', priority=13, submitted_at=1300305712, results=-1), fakedb.BuildRequest(id=21, buildsetid=32, 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): # Allow all requests to test builder functionality return True # check if all are merged res = yield self.bldr._mergeRequests(brdicts[0], brdicts, mergeRequests_fn) self.assertEqual(res, [brdicts[0], brdicts[1], brdicts[2]])
def test_trigger_overlapping(self): sched = self.makeScheduler() self.db.insertTestData([ fakedb.SourceStampSet(id=1091), fakedb.SourceStampSet(id=1092), fakedb.SourceStamp(id=91, sourcestampsetid=1091, revision='myrev1', branch='br', project='p', repository='r'), fakedb.SourceStamp(id=92, sourcestampsetid=1092, revision='myrev2', branch='br', project='p', repository='r'), ]) # no subscription should be in place yet callbacks = self.master.getSubscriptionCallbacks() self.assertEqual(callbacks['buildset_completion'], None) # trigger the scheduler the first time d = sched.trigger(1091) bsid1 = self.db.buildsets.assertBuildset('?', dict(external_idstring=None, properties=[('scheduler', ('n', 'Scheduler'))], reason='Triggerable(n)', sourcestampsetid=1091), {'r': dict(branch='br', project='p', repository='r', revision='myrev1', sourcestampsetid=1091)}) d.addCallback(lambda (res, brids) : self.assertEqual(res, 11) and self.assertEqual(brids, self.db.buildsets.allBuildRequests(bsid1))) # and the second time d = sched.trigger(1092) bsid2 = self.db.buildsets.assertBuildset(bsid1+1, # assumes bsid's are sequential dict(external_idstring=None, properties=[('scheduler', ('n', 'Scheduler'))], reason='Triggerable(n)', sourcestampsetid=1092), {'r': dict(branch='br', project='p', repository='r', revision='myrev2', sourcestampsetid=1092)}) d.addCallback(lambda (res, brids) : self.assertEqual(res, 22) and self.assertEqual(brids, self.db.buildsets.allBuildRequests(bsid2))) # check that the scheduler has subscribed to buildset changes callbacks = self.master.getSubscriptionCallbacks() self.assertNotEqual(callbacks['buildset_completion'], None) # let a few buildsets complete callbacks['buildset_completion'](bsid2+27, 3) callbacks['buildset_completion'](bsid2, 22) callbacks['buildset_completion'](bsid2+7, 3) callbacks['buildset_completion'](bsid1, 11) # both should have triggered with appropriate results, and the # subscription should be cancelled callbacks = self.master.getSubscriptionCallbacks() self.assertEqual(callbacks['buildset_completion'], None)
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_brdictToBuildRequest(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), ]) brdict = yield self.db.buildrequests.getBuildRequest(19) br = yield self.bldr._brdictToBuildRequest(brdict) # 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])
def test_mergeRequests(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), 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]])
def test_updateSourceStamps(self): d = self.insertTestData([ fakedb.SourceStampSet(id=1), fakedb.SourceStamp(id=1, sourcestampsetid=1, branch='b1', revision= None, repository='rep', codebase='c1'), fakedb.SourceStamp(id=2, sourcestampsetid=1, branch='b2', revision= None, repository='rep2', codebase='c2'), ]) d.addCallback(lambda _ : self.db.sourcestamps.getSourceStamp(1)) def checkRevision(ssdict, codebase='', revision=None): self.assertEqual(ssdict['codebase'], codebase) self.assertEqual(ssdict['revision'], revision) d.addCallback(checkRevision, codebase='c1') sourcestamps = [{'b_codebase': 'c1', 'b_revision': 'r1', 'b_sourcestampsetid': 1}, {'b_codebase': 'c2', 'b_revision': 'r2', 'b_sourcestampsetid': 1}] d.addCallback(lambda _ : self.db.sourcestamps.updateSourceStamps(sourcestamps)) def checkUpdate(rowsupdated): self.assertEqual(rowsupdated, 2) d.addCallback(checkUpdate) d.addCallback(lambda _: self.db.sourcestamps.getSourceStamp(1)) d.addCallback(checkRevision, codebase='c1', revision='r1') d.addCallback(lambda _: self.db.sourcestamps.getSourceStamp(2)) d.addCallback(checkRevision, codebase='c2', revision='r2') return d
def test_addSourceStamp_patch(self): # add a sourcestampset for referential integrity d = self.insertTestData([ fakedb.SourceStampSet(id=1), ]) d.addCallback(lambda _ : self.db.sourcestamps.addSourceStamp(branch = 'production', revision='abdef', repository='test://repo', codebase='cb', project='stamper', sourcestampsetid=1, patch_body='my patch', patch_level=3, patch_subdir='master/', patch_author='me', patch_comment="comment")) def check(ssid): def thd(conn): # should see one sourcestamp row ss_tbl = self.db.model.sourcestamps r = conn.execute(ss_tbl.select()) rows = [ (row.id, row.branch, row.revision, row.patchid, row.repository, row.codebase, row.project, row.sourcestampsetid) for row in r.fetchall() ] patchid = row.patchid self.assertNotEqual(patchid, None) self.assertEqual(rows, [ ( ssid, 'production', 'abdef', patchid, 'test://repo', 'cb', 'stamper', 1) ]) # .. and a single patch patches_tbl = self.db.model.patches r = conn.execute(patches_tbl.select()) rows = [ (row.id, row.patchlevel, row.patch_base64, row.subdir, row.patch_author, row.patch_comment) for row in r.fetchall() ] self.assertEqual(rows, [(patchid, 3, 'bXkgcGF0Y2g=', 'master/', 'me', 'comment')]) return self.db.pool.do(thd) d.addCallback(check) return d
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_addBuildsetForSourceStamp_builderNames(self): sched = self.makeScheduler(name='n', builderNames=['k']) 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, builderNames=['a', 'b'])) def check((bsid, brids)): self.db.buildsets.assertBuildset( bsid, dict(reason='whynot', brids=brids, external_idstring=None, properties=[('scheduler', ('n', 'Scheduler'))], sourcestampsetid=1091), { 'cb': dict(branch='fixins', revision='abc', repository='r', codebase='cb', project='p', sourcestampsetid=1091) }) d.addCallback(check) return d
def setUp(self): # 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), ]
def setUp(self): # a collection of rows that would otherwise clutter up every test master_id = fakedb.FakeBuildRequestsComponent.MASTER_ID self.base_rows = [ fakedb.SourceStampSet(id=21), fakedb.SourceStamp(id=21, sourcestampsetid=21), fakedb.Buildset(id=11, reason='because', sourcestampsetid=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), ]
def test_fromBrdict_submittedAt_NULL(self): master = fakemaster.make_master() master.db = fakedb.FakeDBConnector(self) master.db.insertTestData([ fakedb.SourceStampSet(id=234), fakedb.SourceStamp(id=234, sourcestampsetid=234, branch='trunk', revision='9284', repository='svn://...', project='world-domination'), fakedb.Buildset(id=539, reason='triggered', sourcestampsetid=234), fakedb.BuildRequest(id=288, buildsetid=539, buildername='bldr', priority=13, submitted_at=None), ]) # 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): # remaining fields assumed to be checked in test_fromBrdict self.assertEqual(br.submittedAt, None) d.addCallback(check) return d
def setUp(self): self.MASTER_ID = fakedb.FakeBuildRequestsComponent.MASTER_ID self.OTHER_MASTER_ID = self.MASTER_ID + 1111 d = self.setUpConnectorComponent(table_names=[ 'patches', 'changes', 'sourcestamp_changes', 'buildsets', 'buildset_properties', 'buildrequests', 'objects', 'buildrequest_claims', 'sourcestamps', 'sourcestampsets' ]) 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.SourceStampSet(id=234), fakedb.SourceStamp(id=234, sourcestampsetid=234), fakedb.Object(id=self.MASTER_ID, name="fake master", class_name="BuildMaster"), fakedb.Object(id=self.OTHER_MASTER_ID, name="other master", class_name="BuildMaster"), fakedb.Buildset(id=self.BSID, sourcestampsetid=234), ])) return d
def insert1(_): self.db.insertTestData([ fakedb.SourceStampSet(id=127), fakedb.SourceStamp(id=127, sourcestampsetid=127), fakedb.Buildset(id=99, sourcestampsetid=127), fakedb.BuildRequest(id=11, buildsetid=9, buildername='eleventy'), ])
def test_BuildRequestControlCancelBuildRequest(self): master = fakemaster.make_master() master.db = fakedb.FakeDBConnector(self) bldr = mock.Mock(name="bldr") master.db.insertTestData([ fakedb.BuildRequest(id=1, buildsetid=1, buildername='bldr'), fakedb.Buildset(id=1, reason='force', sourcestampsetid=1), fakedb.SourceStampSet(id=1), fakedb.SourceStamp(id=1, sourcestampsetid=1) ]) d = master.db.buildrequests.getBuildRequest(1) def checkCanceled(br): self.assertEquals((br['complete'], br['results']), (True, CANCELED)) d.addCallback(lambda brdict: buildrequest.BuildRequest.fromBrdict( master, brdict)) d.addCallback( lambda breq: buildrequest.BuildRequestControl(bldr, breq)) d.addCallback(lambda breqControl: breqControl.cancel()) d.addCallback(lambda _: master.db.buildrequests.getBuildRequest(1)) d.addCallback(checkCanceled) return d
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
def test_addSourceStamp_simple(self): # add a sourcestampset for referential integrity d = self.insertTestData([ fakedb.SourceStampSet(id=1), ]) d.addCallback(lambda _: self.db.sourcestamps.addSourceStamp( branch='production', revision='abdef', repository='test://repo', codebase='cb', project='stamper', sourcestampsetid=1)) def check(ssid): def thd(conn): # should see one sourcestamp row ss_tbl = self.db.model.sourcestamps r = conn.execute(ss_tbl.select()) rows = [(row.id, row.branch, row.revision, row.patchid, row.repository, row.codebase, row.project, row.sourcestampsetid) for row in r.fetchall()] self.assertEqual(rows, [(ssid, 'production', 'abdef', None, 'test://repo', 'cb', 'stamper', 1)]) # .. and no sourcestamp_changes ssc_tbl = self.db.model.sourcestamp_changes r = conn.execute(ssc_tbl.select()) rows = [1 for row in r.fetchall()] self.assertEqual(rows, []) return self.db.pool.do(thd) d.addCallback(check) return d
def test_getSourceStamp_simple(self): d = self.insertTestData([ fakedb.SourceStampSet(id=234), fakedb.SourceStamp(id=234, sourcestampsetid=234, branch='br', revision='rv', repository='rep', codebase='cb', project='prj'), ]) d.addCallback(lambda _: self.db.sourcestamps.getSourceStamp(234)) def check(ssdict): self.assertEqual( ssdict, dict(ssid=234, branch='br', revision='rv', sourcestampsetid=234, repository='rep', codebase='cb', project='prj', patch_body=None, patch_level=None, patch_subdir=None, patch_author=None, patch_comment=None, changeids=set([]))) d.addCallback(check) return d
def test_addSourceStamp_changes(self): # add some sample changes and a sourcestampset for referential integrity d = self.insertTestData([ fakedb.SourceStampSet(id=1), fakedb.Change(changeid=3), fakedb.Change(changeid=4), ]) d.addCallback(lambda _ : self.db.sourcestamps.addSourceStamp('production', 'abdef', 'test://repo', 'stamper', 1, changeids=[3,4])) def check(ssid): def thd(conn): # should see one sourcestamp row ss_tbl = self.db.model.sourcestamps r = conn.execute(ss_tbl.select()) rows = [ (row.id, row.branch, row.revision, row.patchid, row.repository, row.project, row.sourcestampsetid) for row in r.fetchall() ] self.assertEqual(rows, [ ( ssid, 'production', 'abdef', None, 'test://repo', 'stamper', 1) ]) # .. and two sourcestamp_changes ssc_tbl = self.db.model.sourcestamp_changes r = conn.execute(ssc_tbl.select()) rows = [ (row.sourcestampid, row.changeid) for row in r.fetchall() ] self.assertEqual(sorted(rows), [ (ssid, 3), (ssid, 4) ]) return self.db.pool.do(thd) d.addCallback(check) return d
def test_mergeRequests(self): # set up all of the data required for a BuildRequest object rows = [ 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='A', priority=13, submitted_at=1300305712, results=-1), fakedb.BuildRequest(id=20, buildsetid=30, buildername='A', priority=13, submitted_at=1300305712, results=-1), fakedb.BuildRequest(id=21, 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): # merge evens with evens, odds with odds self.assertIdentical(builder, self.bldr) return breq.id % 2 == other.id % 2 self.bldr.getMergeRequestsFn = lambda: mergeRequests_fn yield self.do_test_maybeStartBuildsOnBuilder(rows=rows, exp_claims=[19, 20, 21], exp_builds=[ ('test-slave1', [19, 21]), ('test-slave2', [20]) ])
def test_buildsetFinished_sends_email(self): fakeBuildMessage = Mock() mn = MailNotifier('*****@*****.**', buildSetSummary=True, mode=("failing", "passing", "warnings"), builders=["Builder1", "Builder2"]) mn.buildMessage = fakeBuildMessage builder1 = Mock() builder1.getBuild = lambda number: build1 builder1.name = "Builder1" build1 = FakeBuildStatus() build1.results = FAILURE build1.finished = True build1.reason = "testReason" build1.getBuilder.return_value = builder1 builder2 = Mock() builder2.getBuild = lambda number: build2 builder2.name = "Builder2" build2 = FakeBuildStatus() build2.results = FAILURE build2.finished = True build2.reason = "testReason" build2.getBuilder.return_value = builder1 def fakeGetBuilder(buildername): return {"Builder1": builder1, "Builder2": builder2}[buildername] self.db = fakedb.FakeDBConnector(self) self.db.insertTestData([ fakedb.SourceStampSet(id=127), fakedb.Buildset(id=99, sourcestampsetid=127, results=SUCCESS, reason="testReason"), fakedb.BuildRequest(id=11, buildsetid=99, buildername='Builder1'), fakedb.Build(number=0, brid=11), fakedb.BuildRequest(id=12, buildsetid=99, buildername='Builder2'), fakedb.Build(number=0, brid=12), ]) mn.master = self # FIXME: Should be FakeMaster self.status = Mock() mn.master_status = Mock() mn.master_status.getBuilder = fakeGetBuilder mn.buildMessageDict = Mock() mn.buildMessageDict.return_value = { "body": "body", "type": "text", "subject": "subject" } mn.buildsetFinished(99, FAILURE) fakeBuildMessage.assert_called_with("(whole buildset)", [build1, build2], SUCCESS)
def test_trigger(self): sched = self.makeScheduler() self.db.insertTestData([ fakedb.SourceStampSet(id=1091), fakedb.SourceStamp(id=91, sourcestampsetid=1091, revision='myrev', branch='br', project='p', repository='r'), ]) # no subscription should be in place yet callbacks = self.master.getSubscriptionCallbacks() self.assertEqual(callbacks['buildset_completion'], None) # trigger the scheduler, exercising properties while we're at it set_props = properties.Properties() set_props.setProperty('pr', 'op', 'test') d = sched.trigger(1091, set_props=set_props) bsid = self.db.buildsets.assertBuildset('?', dict(external_idstring=None, properties=[ ('pr', ('op', 'test')), ('scheduler', ('n', 'Scheduler')), ], reason='Triggerable(n)', sourcestampsetid=1091), {'r': dict(branch='br', project='p', repository='r', revision='myrev', sourcestampsetid=1091) }) # set up a boolean so that we can know when the deferred fires self.fired = False def fired((result, brids)): self.assertEqual(result, 13) # 13 comes from the result below self.assertEqual(brids, self.db.buildsets.allBuildRequests(bsid)) self.fired = True d.addCallback(fired) # check that the scheduler has subscribed to buildset changes, but # not fired yet callbacks = self.master.getSubscriptionCallbacks() self.assertNotEqual(callbacks['buildset_completion'], None) self.assertFalse(self.fired) # pretend a non-matching buildset is complete callbacks['buildset_completion'](bsid+27, 3) # scheduler should not have reacted callbacks = self.master.getSubscriptionCallbacks() self.assertNotEqual(callbacks['buildset_completion'], None) self.assertFalse(self.fired) # pretend the matching buildset is complete callbacks['buildset_completion'](bsid, 13) # scheduler should have reacted callbacks = self.master.getSubscriptionCallbacks() self.assertEqual(callbacks['buildset_completion'], None) self.assertTrue(self.fired)
def test_buildsetFinished_sends_email(self): fakeBuildMessage = Mock() mn = MailNotifier('*****@*****.**', buildSetSummary=True, mode=("failing", "passing", "warnings"), builders=["Builder"]) mn.buildMessage = fakeBuildMessage def fakeGetBuild(number): return build def fakeGetBuilder(buildername): if buildername == builder.name: return builder return None def fakeGetBuildRequests(self, bsid): return defer.succeed([{"buildername": "Builder", "brid": 1}]) builder = Mock() builder.getBuild = fakeGetBuild builder.name = "Builder" build = FakeBuildStatus() build.results = FAILURE build.finished = True build.reason = "testReason" build.getBuilder.return_value = builder self.db = fakedb.FakeDBConnector(self) self.db.insertTestData([ fakedb.SourceStampSet(id=127), fakedb.Buildset(id=99, sourcestampsetid=127, results=SUCCESS, reason="testReason"), fakedb.BuildRequest(id=11, buildsetid=99, buildername='Builder'), fakedb.Build(number=0, brid=11), ]) mn.master = self # FIXME: Should be FakeMaster self.status = Mock() mn.master_status = Mock() mn.master_status.getBuilder = fakeGetBuilder mn.buildMessageDict = Mock() mn.buildMessageDict.return_value = { "body": "body", "type": "text", "subject": "subject" } mn.buildsetFinished(99, FAILURE) fakeBuildMessage.assert_called_with("Buildset Complete: testReason", [build], SUCCESS)
def insertRecentBuilds(self): builds = [{ 'buildername': "builder", 'submitted_at': 1457706077, 'complete_at': 1457706089, 'revision': 'abzdewf', 'slavename': 'slave-02' }, { 'buildername': "builder", 'submitted_at': 1457895804, 'complete_at': 1457895819, 'revision': 'zbzdewf', 'slavename': 'slave-01' }, { 'buildername': "builder-01", 'submitted_at': 1457895804, 'complete_at': 1457895819, 'revision': 'zbzdewf', 'slavename': 'slave-01' }, { 'buildername': "builder", 'submitted_at': self.SUBMITTED_AT_EPOCH, 'complete_at': self.COMPLETE_AT_EPOCH, 'revision': 'fwbzdeif', 'slavename': 'slave-01' }] recent_builds = [] for idx, b in enumerate(builds): rowid = idx + 1 recent_builds += [ fakedb.BuildRequest(id=rowid, buildsetid=rowid, buildername=b['buildername'], complete=1, results=SUCCESS, submitted_at=b['submitted_at'], complete_at=b['complete_at']), fakedb.Buildset(id=rowid, sourcestampsetid=rowid), fakedb.SourceStampSet(id=rowid), fakedb.SourceStamp(id=rowid, revision=b['revision'], codebase='1', sourcestampsetid=rowid, branch='master', repository='z'), fakedb.Build(id=rowid, number=rowid, brid=rowid, start_time=b['submitted_at'], finish_time=b['complete_at'], slavename=b['slavename']) ] yield self.insertTestData(recent_builds)
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')