Skip to content

Commit

Permalink
Merge pull request #1839 from prasoon2211/stats-service-fix
Browse files Browse the repository at this point in the history
Added sanity check for  parameter for CaptureBuildDuration.
  • Loading branch information
Mikhail Sobolev committed Sep 6, 2015
2 parents b7a4e04 + eca33d9 commit 21cad31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions master/buildbot/statistics/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from twisted.internet import defer
from twisted.internet import threads

from buildbot import config
from buildbot.errors import CaptureCallbackError


Expand Down Expand Up @@ -266,6 +267,11 @@ class CaptureBuildDuration(CaptureBuildTimes):
"""

def __init__(self, builder_name, report_in='seconds', callback=None):
if report_in not in ['seconds', 'minutes', 'hours']:
config.error("Error during initialization of class %s."
" `report_in` parameter must be one of 'seconds', 'minutes' or 'hours'"
% (self.__class__.__name__))

def default_callback(start_time, end_time):
divisor = 1
# it's a closure
Expand Down
4 changes: 4 additions & 0 deletions master/buildbot/test/unit/test_stats_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ def test_build_duration_capturing_hours(self):
yield self.build_time_capture_helper('hours')
self.assertEqual('duration', self.fake_storage_service.stored_data[0][0].keys()[0])

def test_build_duration_report_in_error(self):
self.assertRaises(config.ConfigErrors,
lambda: capture.CaptureBuildDuration('builder1', report_in='foobar'))

@defer.inlineCallbacks
def test_build_duration_capturing_alt_callback(self):
def cb(*args, **kwargs):
Expand Down

0 comments on commit 21cad31

Please sign in to comment.