Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import collections | 6 import collections |
| 7 import copy | 7 import copy |
| 8 import datetime | 8 import datetime |
| 9 import itertools | 9 import itertools |
| 10 import logging | 10 import logging |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 '99': 98.01, | 362 '99': 98.01, |
| 363 'max': 99.0, | 363 'max': 99.0, |
| 364 'mean': 49.5, | 364 'mean': 49.5, |
| 365 'min': 0.0, | 365 'min': 0.0, |
| 366 'size': 100.0, | 366 'size': 100.0, |
| 367 }, stats) | 367 }, stats) |
| 368 | 368 |
| 369 self.assertEqual(cq_stats.derive_list_stats([])['size'], 1) | 369 self.assertEqual(cq_stats.derive_list_stats([])['size'], 1) |
| 370 | 370 |
| 371 def get_mock_derive_patch_stats(self, supported=True): | 371 def get_mock_derive_patch_stats(self, supported=True): |
| 372 def mock_derive_patch_stats(_, patch_id): | 372 def mock_derive_patch_stats(_begin_date, _end_date, patch_id): |
|
Adrian Kuegel
2015/05/26 14:40:47
nit: I think this should be just begin_date and en
Paweł Hajdan Jr.
2015/05/27 09:19:56
That triggers pylint warnings. I'm leaving the cod
| |
| 373 # The original function expects patch_id to be a 2-tuple. | 373 # The original function expects patch_id to be a 2-tuple. |
| 374 self.assertIsInstance(patch_id, tuple) | 374 self.assertIsInstance(patch_id, tuple) |
| 375 self.assertEqual(len(patch_id), 2) | 375 self.assertEqual(len(patch_id), 2) |
| 376 # Note: these fields are required by derive_stats(). Make sure | 376 # Note: these fields are required by derive_stats(). Make sure |
| 377 # they are present in the unit tests for derive_patch_stats(). | 377 # they are present in the unit tests for derive_patch_stats(). |
| 378 stats = { | 378 stats = { |
| 379 'attempts': 3, | 379 'attempts': 3, |
| 380 'false-rejections': 1, | 380 'false-rejections': 1, |
| 381 'rejections': 2, | 381 'rejections': 2, |
| 382 'committed': True, | 382 'committed': True, |
| 383 'patchset-duration-wallclock': 1234.56, | 383 'patchset-duration-wallclock': 1234.56, |
| 384 'patchset-duration': 999.99, | 384 'patchset-duration': 999.99, |
| 385 'failed-jobs-details': {'tester': 2}, | 385 'failed-jobs-details': {'tester': 2}, |
| 386 'supported': supported, | 386 'supported': supported, |
| 387 } | 387 } |
| 388 return patch_id, stats | 388 return patch_id, stats |
| 389 return mock_derive_patch_stats | 389 return mock_derive_patch_stats |
| 390 | 390 |
| 391 def test_derive_stats(self): | 391 def test_derive_stats(self): |
| 392 # Unused args: pylint: disable=W0613 | 392 # Unused args: pylint: disable=W0613 |
| 393 def mock_fetch_cq_logs_0(begin_date=None, end_date=None, filters=None): | 393 def mock_fetch_cq_logs_0(start_date=None, end_date=None, filters=None): |
| 394 return [] | 394 return [] |
| 395 # Unused args: pylint: disable=W0613 | 395 # Unused args: pylint: disable=W0613 |
| 396 def mock_fetch_cq_logs(begin_date=None, end_date=None, filters=None): | 396 def mock_fetch_cq_logs(start_date=None, end_date=None, filters=None): |
| 397 return [ | 397 return [ |
| 398 {'fields': {'issue': 12345, 'patchset': 1}, | 398 {'fields': {'issue': 12345, 'patchset': 1}, |
| 399 'timestamp': 1415150483.18568, | 399 'timestamp': 1415150483.18568, |
| 400 }, | 400 }, |
| 401 ] | 401 ] |
| 402 | 402 |
| 403 self.mock(cq_stats, 'derive_patch_stats', self.get_mock_derive_patch_stats( | 403 self.mock(cq_stats, 'derive_patch_stats', self.get_mock_derive_patch_stats( |
| 404 supported=True)) | 404 supported=True)) |
| 405 # Test empty logs. | 405 # Test empty logs. |
| 406 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs_0) | 406 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs_0) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 attempt('Try jobs failed:\n test_dbg', reason='simple try job'), | 479 attempt('Try jobs failed:\n test_dbg', reason='simple try job'), |
| 480 attempt('Try jobs failed:\n chromium_presubmit'), | 480 attempt('Try jobs failed:\n chromium_presubmit'), |
| 481 attempt('Exceeded time limit waiting for builds to trigger'), | 481 attempt('Exceeded time limit waiting for builds to trigger'), |
| 482 attempt('Some totally random unknown reason') + [ | 482 attempt('Some totally random unknown reason') + [ |
| 483 {'fields': {'action': 'random garbage'}, | 483 {'fields': {'action': 'random garbage'}, |
| 484 'timestamp': time_obj['time'] + 0.5}], | 484 'timestamp': time_obj['time'] + 0.5}], |
| 485 attempt('', commit=True), | 485 attempt('', commit=True), |
| 486 ] | 486 ] |
| 487 | 487 |
| 488 # Dangerous default value, unused args: pylint: disable=W0102,W0613 | 488 # Dangerous default value, unused args: pylint: disable=W0102,W0613 |
| 489 def mock_fetch_cq_logs(begin_date=None, end_date=None, filters=[]): | 489 def mock_fetch_cq_logs(start_date=None, end_date=None, filters=[]): |
| 490 entries = list(itertools.chain(*attempts)) | 490 entries = list(itertools.chain(*attempts)) |
| 491 entries.reverse() | 491 entries.reverse() |
| 492 return entries | 492 return entries |
| 493 | 493 |
| 494 # Dangerous default value, unused args: pylint: disable=W0102,W0613 | 494 # Dangerous default value, unused args: pylint: disable=W0102,W0613 |
| 495 def mock_fetch_cq_logs_0(begin_date=None, end_date=None, filters=[]): | 495 def mock_fetch_cq_logs_0(start_date=None, end_date=None, filters=[]): |
| 496 return [] | 496 return [] |
| 497 | 497 |
| 498 # Dangerous default value, unused args: pylint: disable=W0102,W0613 | 498 # Dangerous default value, unused args: pylint: disable=W0102,W0613 |
| 499 def mock_fetch_cq_logs_junk(begin_date=None, end_date=None, filters=[]): | 499 def mock_fetch_cq_logs_junk(start_date=None, end_date=None, filters=[]): |
| 500 return [{'fields': {'action': 'cq_start'}, 'timestamp': 1415150662.3}] | 500 return [{'fields': {'action': 'cq_start'}, 'timestamp': 1415150662.3}] |
| 501 | 501 |
| 502 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs) | 502 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs) |
| 503 | 503 |
| 504 patch_id = ('pid', 5) | 504 patch_id = ('pid', 5) |
| 505 pid, stats = cq_stats.derive_patch_stats( | 505 pid, stats = cq_stats.derive_patch_stats( |
| 506 datetime.datetime(2014, 10, 15), patch_id) | 506 datetime.datetime(2014, 10, 15), |
| 507 datetime.datetime(2014, 10, 15), | |
| 508 patch_id) | |
| 507 self.assertEqual(patch_id, pid) | 509 self.assertEqual(patch_id, pid) |
| 508 # Check required fields in the result. | 510 # Check required fields in the result. |
| 509 mock_derive_patch_stats = self.get_mock_derive_patch_stats() | 511 mock_derive_patch_stats = self.get_mock_derive_patch_stats() |
| 510 for k in mock_derive_patch_stats(None, patch_id)[1]: | 512 for k in mock_derive_patch_stats(None, None, patch_id)[1]: |
| 511 self.assertIsNotNone(stats.get(k)) | 513 self.assertIsNotNone(stats.get(k)) |
| 512 # A few sanity checks. | 514 # A few sanity checks. |
| 513 self.assertEqual(stats['attempts'], len(attempts)) | 515 self.assertEqual(stats['attempts'], len(attempts)) |
| 514 self.assertEqual(stats['committed'], True) | 516 self.assertEqual(stats['committed'], True) |
| 515 self.assertGreater(stats['false-rejections'], 0) | 517 self.assertGreater(stats['false-rejections'], 0) |
| 516 | 518 |
| 517 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs_0) | 519 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs_0) |
| 518 pid, stats = cq_stats.derive_patch_stats( | 520 pid, stats = cq_stats.derive_patch_stats( |
| 519 datetime.datetime(2014, 10, 15), patch_id) | 521 datetime.datetime(2014, 10, 15), |
| 522 datetime.datetime(2014, 10, 15), | |
| 523 patch_id) | |
| 520 # Cover the case when there are actions, but no CQ attempts. | 524 # Cover the case when there are actions, but no CQ attempts. |
| 521 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs_junk) | 525 self.mock(cq_stats, 'fetch_cq_logs', mock_fetch_cq_logs_junk) |
| 522 pid, stats = cq_stats.derive_patch_stats( | 526 pid, stats = cq_stats.derive_patch_stats( |
| 523 datetime.datetime(2014, 10, 15), patch_id) | 527 datetime.datetime(2014, 10, 15), |
| 528 datetime.datetime(2014, 10, 15), | |
| 529 patch_id) | |
| 524 | 530 |
| 525 | 531 |
| 526 def test_derive_tree_stats(self): | 532 def test_derive_tree_stats(self): |
| 527 def makeDate(days=0, hours=0, minutes=0, seconds=0): | 533 def makeDate(days=0, hours=0, minutes=0, seconds=0): |
| 528 start_date = datetime.datetime(2014, 10, 1, 15, 20, 12, 345) | 534 start_date = datetime.datetime(2014, 10, 1, 15, 20, 12, 345) |
| 529 return start_date + datetime.timedelta( | 535 return start_date + datetime.timedelta( |
| 530 days=days, seconds=hours*3600+minutes*60+seconds) | 536 days=days, seconds=hours*3600+minutes*60+seconds) |
| 531 | 537 |
| 532 events = [ | 538 events = [ |
| 533 {'date': makeDate(-1), | 539 {'date': makeDate(-1), |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 cq_stats.acquire_stats(Args( | 696 cq_stats.acquire_stats(Args( |
| 691 project='chromium', bots=[], use_logs=True, range='hour')) | 697 project='chromium', bots=[], use_logs=True, range='hour')) |
| 692 | 698 |
| 693 def test_main(self): | 699 def test_main(self): |
| 694 self.mock(cq_stats, 'output', self.print_mock) | 700 self.mock(cq_stats, 'output', self.print_mock) |
| 695 self.mock(cq_stats, 'parse_args', lambda: Args( | 701 self.mock(cq_stats, 'parse_args', lambda: Args( |
| 696 project='chromium', log_level=logging.CRITICAL, logs_black_list=None)) | 702 project='chromium', log_level=logging.CRITICAL, logs_black_list=None)) |
| 697 self.mock(cq_stats, 'acquire_stats', lambda _: cq_stats.default_stats()) | 703 self.mock(cq_stats, 'acquire_stats', lambda _: cq_stats.default_stats()) |
| 698 cq_stats.main() | 704 cq_stats.main() |
| 699 return self.expectations | 705 return self.expectations |
| OLD | NEW |