Skip to content

Commit

Permalink
bug 977917 - totalNumberOfCrashes returned by tcbs is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
rhelmer committed Mar 3, 2014
1 parent c9dc376 commit 59be021
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
9 changes: 6 additions & 3 deletions socorro/external/postgresql/tcbs.py
Expand Up @@ -116,7 +116,8 @@ def getListOfTopCrashersBySignature(connection, dbParams):
version_list,
%s / total_crashes::float as percent_of_total,
startup_count / %s::float as startup_percent,
is_gc_count
is_gc_count,
total_crashes::int
FROM tcbs_window
ORDER BY %s DESC
LIMIT %s
Expand Down Expand Up @@ -202,7 +203,7 @@ def listOfListsWithChangeInRank(listOfQueryResultsIterable):
'plugin_count', 'content_count',
'first_report_exact', 'versions',
'percentOfTotal', 'startup_percent',
'is_gc_count'], aRow))
'is_gc_count', 'total_crashes'], aRow))
aRowAsDict['currentRank'] = rank
aRowAsDict['first_report'] = (
aRowAsDict['first_report_exact'].strftime('%Y-%m-%d'))
Expand Down Expand Up @@ -293,7 +294,9 @@ def twoPeriodTopCrasherComparison(
#context['logger'].debug('listOfTopCrashers %s' % listOfTopCrashers)
totalNumberOfCrashes = totalPercentOfTotal = 0
for x in listOfTopCrashers:
totalNumberOfCrashes += x.get('count', 0)
if 'total_crashes' in x:
totalNumberOfCrashes = x['total_crashes']
del x['total_crashes']
totalPercentOfTotal += x.get('percentOfTotal', 0)

result = {
Expand Down
51 changes: 49 additions & 2 deletions socorro/unittest/external/postgresql/test_tcbs.py
Expand Up @@ -247,7 +247,8 @@ def test_listOfListsWithChangeInRank(self):
'signature': 'Fake Signature #1',
'versions_count': 2,
'previousPercentOfTotal': 0.58333333333333304,
'plugin_count': 0
'plugin_count': 0,
'total_crashes': 8
}, {
'count': 3L,
'mac_count': 1L,
Expand All @@ -268,7 +269,8 @@ def test_listOfListsWithChangeInRank(self):
'signature': 'Fake Signature #2',
'versions_count': 6,
'previousPercentOfTotal': 0.41666666666666702,
'plugin_count': 0
'plugin_count': 0,
'total_crashes': 8
}]]

self.assertEqual(res, res_expected)
Expand Down Expand Up @@ -355,3 +357,48 @@ def test_twoPeriodTopCrasherComparison(self):
}

self.assertEqual(res, res_expected)

#--------------------------------------------------------------------------
def test_twoPeriodTopCrasherComparisonLimited(self):

lastweek = self.now - datetime.timedelta(days=7)
lastweek_str = datetimeutil.date_to_string(lastweek.date())
two_weeks = datetimeutil.date_to_string(self.now.date() -
datetime.timedelta(days=14))

self.params.limit = 1
res = tcbs.twoPeriodTopCrasherComparison(
self.connection,
self.params
)

res_expected = {
'totalPercentage': 0.58333333333333304,
'end_date': lastweek_str,
'start_date': two_weeks,
'crashes': [{
'count': 14L,
'mac_count': 1L,
'content_count': 0,
'first_report': lastweek_str,
'previousRank': 'null',
'currentRank': 0,
'startup_percent': None,
'versions': 'plugin1, plugin2',
'first_report_exact': lastweek_str + ' 00:00:00',
'percentOfTotal': 0.58333333333333304,
'changeInRank': 'new',
'is_gc_count': 1L,
'win_count': 12L,
'changeInPercentOfTotal': 'new',
'linux_count': 1L,
'hang_count': 0L,
'signature': 'Fake Signature #1',
'versions_count': 2,
'previousPercentOfTotal': 'null',
'plugin_count': 0
}],
'totalNumberOfCrashes': 24L
}

self.assertEqual(res, res_expected)

0 comments on commit 59be021

Please sign in to comment.