Skip to content

Commit

Permalink
Merge andrewjcg/buildbot:cache_bsprops (PR #1152)
Browse files Browse the repository at this point in the history
+autopep8
  • Loading branch information
djmitche committed May 22, 2014
2 parents d758f59 + b4884ca commit 92d9409
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
18 changes: 16 additions & 2 deletions master/buildbot/db/buildsets.py
Expand Up @@ -23,18 +23,25 @@
from buildbot.util import datetime2epoch
from buildbot.util import epoch2datetime
from buildbot.util import json
from twisted.internet import defer
from twisted.internet import reactor


class BsDict(dict):
pass


class BsProps(dict):
pass


class BuildsetsConnectorComponent(base.DBConnectorComponent):
# Documentation is in developer/database.rst

@defer.inlineCallbacks
def addBuildset(self, sourcestampsetid, reason, properties, builderNames,
external_idstring=None, _reactor=reactor):

def thd(conn):
buildsets_tbl = self.db.model.buildsets
submitted_at = _reactor.seconds()
Expand Down Expand Up @@ -86,7 +93,13 @@ def thd(conn):
transaction.commit()

return (bsid, brids)
return self.db.pool.do(thd)

bsid, brids = yield self.db.pool.do(thd)

# Seed the buildset property cache.
self.getBuildsetProperties.cache.put(bsid, BsProps(properties))

defer.returnValue((bsid, brids))

def completeBuildset(self, bsid, results, complete_at=None,
_reactor=reactor):
Expand Down Expand Up @@ -163,6 +176,7 @@ def thd(conn):
for row in res.fetchall()]))
return self.db.pool.do(thd)

@base.cached("BuildsetProperties")
def getBuildsetProperties(self, buildsetid):
"""
Return the properties for a buildset, in the same format they were
Expand All @@ -189,7 +203,7 @@ def thd(conn):
tuple(properties)))
except ValueError:
pass
return dict(l)
return BsProps(l)
return self.db.pool.do(thd)

def _row2dict(self, row):
Expand Down
24 changes: 24 additions & 0 deletions master/buildbot/test/unit/test_db_buildsets.py
Expand Up @@ -14,6 +14,7 @@
# Copyright Buildbot Team Members

import datetime
import mock

from buildbot.db import buildsets
from buildbot.test.fake import fakedb
Expand Down Expand Up @@ -455,3 +456,26 @@ def check(bsdictlist):
self.assertEqual(bsdictlist, [])
d.addCallback(check)
return d

@defer.inlineCallbacks
def test_addBuildset_properties_cache(self):
"""
Test that `addChange` properly seeds the `getChange` cache.
"""

# Patchup the buildset properties cache so we can verify that
# it got called form `addBuildset`.
mockedCachePut = mock.Mock()
self.patch(
self.db.buildsets.getBuildsetProperties.cache,
"put", mockedCachePut)

# Setup a dummy set of properties to insert with the buildset.
props = dict(prop=(['list'], 'test'))

# Now, call `addBuildset`, and verify that the above properties
# were seeed in the `getBuildsetProperties` cache.
bsid, _ = yield self.db.buildsets.addBuildset(
sourcestampsetid=234, reason='because',
properties=props, builderNames=['a', 'b'])
mockedCachePut.assert_called_once_with(bsid, props)

0 comments on commit 92d9409

Please sign in to comment.