Skip to content

Commit

Permalink
Test for mixed failure of classifyChanges
Browse files Browse the repository at this point in the history
Test for an insert failure midway through a classification, in which
case the rollback shouldn't roll back any successful inserts.

Fixes #2696.

(Backport of d8d3753)
  • Loading branch information
djmitche committed Mar 26, 2015
1 parent 05ada3b commit 0fdf835
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions master/buildbot/db/schedulers.py
Expand Up @@ -24,13 +24,13 @@ class SchedulersConnectorComponent(base.DBConnectorComponent):

def classifyChanges(self, objectid, classifications):
def thd(conn):
transaction = conn.begin()
tbl = self.db.model.scheduler_changes
ins_q = tbl.insert()
upd_q = tbl.update(
((tbl.c.objectid == objectid)
& (tbl.c.changeid == sa.bindparam('wc_changeid'))))
for changeid, important in classifications.items():
transaction = conn.begin()
# convert the 'important' value into an integer, since that
# is the column type
imp_int = important and 1 or 0
Expand All @@ -48,7 +48,7 @@ def thd(conn):
wc_changeid=changeid,
important=imp_int)

transaction.commit()
transaction.commit()
return self.db.pool.do(thd)

def flushChangeClassifications(self, objectid, less_than=None):
Expand Down
17 changes: 13 additions & 4 deletions master/buildbot/test/unit/test_db_schedulers.py
Expand Up @@ -85,14 +85,21 @@ def thd(conn):

def test_classifyChanges_again(self):
# test reclassifying changes, which may happen during some timing
# conditions
# conditions. It's important that this test uses multiple changes,
# only one of which already exists
d = self.insertTestData([
# conditions. It's important that this test uses multiple changes,
# only one of which already exists
self.change3,
self.change4,
self.change5,
self.change6,
self.scheduler24,
fakedb.SchedulerChange(objectid=24, changeid=3, important=0),
fakedb.SchedulerChange(objectid=24, changeid=5, important=0),
])
d.addCallback(lambda _:
self.db.schedulers.classifyChanges(24, {3: True}))
self.db.schedulers.classifyChanges(
24, {3: True, 4: False, 5: True, 6: False}))

def check(_):
def thd(conn):
Expand All @@ -101,7 +108,9 @@ def thd(conn):
r = conn.execute(q)
rows = [(row.objectid, row.changeid, row.important)
for row in r.fetchall()]
self.assertEqual(rows, [(24, 3, 1)])
self.assertEqual(sorted(rows),
sorted([(24, 3, 1), (24, 4, 0),
(24, 5, 1), (24, 6, 0)]))
return self.db.pool.do(thd)
d.addCallback(check)
return d
Expand Down

0 comments on commit 0fdf835

Please sign in to comment.