Mercurial > bitten > bitten-test
changeset 450:9d0651c819a8
Proper fix for #165, [493] was broken. This time with added tests.
author | cmlenz |
---|---|
date | Thu, 23 Aug 2007 22:51:36 +0000 |
parents | 01503ed994e7 |
children | 57822fefd441 |
files | bitten/model.py bitten/queue.py bitten/tests/queue.py |
diffstat | 3 files changed, 88 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/model.py +++ b/bitten/model.py @@ -44,6 +44,9 @@ self.label = label or '' self.description = description or '' + def __repr__(self): + return '<%s %r>' % (type(self).__name__, self.name) + exists = property(fget=lambda self: self._old_name is not None, doc='Whether this configuration exists in the database') @@ -199,6 +202,9 @@ self.name = name self.rules = [] + def __repr__(self): + return '<%s %r>' % (type(self).__name__, self.id) + exists = property(fget=lambda self: self.id is not None, doc='Whether this target platform exists in the database') @@ -363,6 +369,9 @@ self.status = status self.slave_info = {} + def __repr__(self): + return '<%s %r>' % (type(self).__name__, self.id) + exists = property(fget=lambda self: self.id is not None, doc='Whether this build exists in the database') completed = property(fget=lambda self: self.status != Build.IN_PROGRESS,
--- a/bitten/queue.py +++ b/bitten/queue.py @@ -215,7 +215,18 @@ builds = [] for config in BuildConfig.select(self.env, db=db): + platforms = [] for platform, rev, build in collect_changes(repos, config, db): + + if not self.build_all and platform.id in platforms: + # We've seen this platform already, so these are older + # builds that should only be built if built_all=True + self.log.debug('Ignoring older revisions for configuration ' + '%r on %r', config.name, platform.name) + break + + platforms.append(platform.id) + if build is None: self.log.info('Enqueuing build of configuration "%s" at ' 'revision [%s] on %s', config.name, rev, @@ -230,12 +241,6 @@ platform=platform.id, rev=str(rev), rev_time=rev_time) builds.append(build) - break - - if not self.build_all: - self.log.debug('Ignoring older revisions for configuration ' - '%r on %r', config.name, platform.name) - continue for build in builds: build.insert(db=db)
--- a/bitten/tests/queue.py +++ b/bitten/tests/queue.py @@ -190,6 +190,74 @@ build = queue.get_build_for_slave('foobar', {}) self.assertEqual(None, build) + def test_populate_not_build_all(self): + self.env.get_repository = lambda authname=None: Mock( + get_changeset=lambda rev: Mock(date=rev * 1000), + get_node=lambda path, rev=None: Mock( + get_entries=lambda: [Mock(), Mock()], + get_history=lambda: [('somepath', 123, 'edit'), + ('somepath', 121, 'edit'), + ('somepath', 120, 'edit')] + ), + normalize_path=lambda path: path, + rev_older_than=lambda rev1, rev2: rev1 < rev2 + ) + BuildConfig(self.env, 'test', path='somepath', active=True).insert() + platform1 = TargetPlatform(self.env, config='test', name='P1') + platform1.insert() + platform2 = TargetPlatform(self.env, config='test', name='P2') + platform2.insert() + + queue = BuildQueue(self.env) + queue.populate() + queue.populate() + queue.populate() + + builds = list(Build.select(self.env, config='test')) + self.assertEqual(2, len(builds)) + self.assertEqual(platform1.id, builds[0].platform) + self.assertEqual('123', builds[0].rev) + self.assertEqual(platform2.id, builds[1].platform) + self.assertEqual('123', builds[1].rev) + + def test_populate_build_all(self): + self.env.get_repository = lambda authname=None: Mock( + get_changeset=lambda rev: Mock(date=rev * 1000), + get_node=lambda path, rev=None: Mock( + get_entries=lambda: [Mock(), Mock()], + get_history=lambda: [('somepath', 123, 'edit'), + ('somepath', 121, 'edit'), + ('somepath', 120, 'edit')] + ), + normalize_path=lambda path: path, + rev_older_than=lambda rev1, rev2: rev1 < rev2 + ) + BuildConfig(self.env, 'test', path='somepath', active=True).insert() + platform1 = TargetPlatform(self.env, config='test', name='P1') + platform1.insert() + platform2 = TargetPlatform(self.env, config='test', name='P2') + platform2.insert() + + queue = BuildQueue(self.env, build_all=True) + queue.populate() + queue.populate() + queue.populate() + + builds = list(Build.select(self.env, config='test')) + self.assertEqual(6, len(builds)) + self.assertEqual(platform1.id, builds[0].platform) + self.assertEqual('123', builds[0].rev) + self.assertEqual(platform2.id, builds[1].platform) + self.assertEqual('123', builds[1].rev) + self.assertEqual(platform1.id, builds[2].platform) + self.assertEqual('121', builds[2].rev) + self.assertEqual(platform2.id, builds[3].platform) + self.assertEqual('121', builds[3].rev) + self.assertEqual(platform1.id, builds[4].platform) + self.assertEqual('120', builds[4].rev) + self.assertEqual(platform2.id, builds[5].platform) + self.assertEqual('120', builds[5].rev) + def test_reset_orphaned_builds(self): BuildConfig(self.env, 'test').insert() platform = TargetPlatform(self.env, config='test', name='Foo')