Commit c3ee1e91 authored by aiolos's avatar aiolos Committed by Commit bot

Better error messages on archive failures, and stop running with partial page...

Better error messages on archive failures, and stop running with partial page sets in user_story_runner.

BUG=435063

Review URL: https://codereview.chromium.org/748013003

Cr-Commit-Position: refs/heads/master@{#307074}
parent 9817ac49
...@@ -201,7 +201,10 @@ def Run(test, user_story_set, expectations, finder_options, results): ...@@ -201,7 +201,10 @@ def Run(test, user_story_set, expectations, finder_options, results):
# patch. # patch.
isinstance(user_story_set, page_set_module.PageSet)): isinstance(user_story_set, page_set_module.PageSet)):
_UpdateUserStoryArchivesIfChanged(user_story_set) _UpdateUserStoryArchivesIfChanged(user_story_set)
user_stories = _CheckArchives(user_story_set, user_stories, results) if not _CheckArchives(
user_story_set.archive_data_file, user_story_set.wpr_archive_info,
user_story_set.pages):
return
for user_story in list(user_stories): for user_story in list(user_stories):
if not test.CanRunForPage(user_story): if not test.CanRunForPage(user_story):
...@@ -275,51 +278,57 @@ def _ShuffleAndFilterUserStorySet(user_story_set, finder_options): ...@@ -275,51 +278,57 @@ def _ShuffleAndFilterUserStorySet(user_story_set, finder_options):
return user_stories return user_stories
def _CheckArchives(page_set, pages, results): def _CheckArchives(archive_data_file, wpr_archive_info, pages):
"""Returns a subset of pages that are local or have WPR archives. """Verifies that all pages are local or have WPR archives.
Logs warnings if any are missing. Logs warnings and returns False if any are missing.
""" """
# Warn of any problems with the entire page set. # Report any problems with the entire page set.
if any(not p.is_local for p in pages): if any(not p.is_local for p in pages):
if not page_set.archive_data_file: if not archive_data_file:
logging.warning('The page set is missing an "archive_data_file" ' logging.error('The page set is missing an "archive_data_file" '
'property. Skipping any live sites. To include them, ' 'property.\nTo run from live sites pass the flag '
'pass the flag --use-live-sites.') '--use-live-sites.\nTo create an archive file add an '
if not page_set.wpr_archive_info: 'archive_data_file property to the page set and then '
logging.warning('The archive info file is missing. ' 'run record_wpr.')
'To fix this, either add svn-internal to your ' return False
'.gclient using http://goto/read-src-internal, ' if not wpr_archive_info:
'or create a new archive using record_wpr.') logging.error('The archive info file is missing.\n'
'To fix this, either add svn-internal to your '
# Warn of any problems with individual pages and return valid pages. '.gclient using http://goto/read-src-internal, '
'or create a new archive using record_wpr.')
return False
# Report any problems with individual pages.
pages_missing_archive_path = [] pages_missing_archive_path = []
pages_missing_archive_data = [] pages_missing_archive_data = []
valid_pages = []
for page in pages: for page in pages:
if not page.is_local and not page.archive_path: if not page.is_local and not page.archive_path:
pages_missing_archive_path.append(page) pages_missing_archive_path.append(page)
elif not page.is_local and not os.path.isfile(page.archive_path): elif not page.is_local and not os.path.isfile(page.archive_path):
pages_missing_archive_data.append(page) pages_missing_archive_data.append(page)
else:
valid_pages.append(page)
if pages_missing_archive_path: if pages_missing_archive_path:
logging.warning('The page set archives for some pages do not exist. ' logging.error('The page set archives for some pages do not exist.\n'
'Skipping those pages. To fix this, record those pages ' 'To fix this, record those pages using record_wpr.\n'
'using record_wpr. To ignore this warning and run ' 'To ignore this warning and run against live sites, '
'against live sites, pass the flag --use-live-sites.') 'pass the flag --use-live-sites.')
logging.error(
'Pages without archives: %s',
', '.join(page.display_name for page in pages_missing_archive_path))
if pages_missing_archive_data: if pages_missing_archive_data:
logging.warning('The page set archives for some pages are missing. ' logging.error('The page set archives for some pages are missing.\n'
'Someone forgot to check them in, or they were deleted. ' 'Someone forgot to check them in, uploaded them to the '
'Skipping those pages. To fix this, record those pages ' 'wrong cloud storage bucket, or they were deleted.\n'
'using record_wpr. To ignore this warning and run ' 'To fix this, record those pages using record_wpr.\n'
'against live sites, pass the flag --use-live-sites.') 'To ignore this warning and run against live sites, '
for page in pages_missing_archive_path + pages_missing_archive_data: 'pass the flag --use-live-sites.')
results.WillRunPage(page) logging.error(
results.AddValue(failure.FailureValue.FromMessage( 'Pages missing archives: %s',
page, 'Page set archive doesn\'t exist.')) ', '.join(page.display_name for page in pages_missing_archive_data))
results.DidRunPage(page) if pages_missing_archive_path or pages_missing_archive_data:
return valid_pages return False
# Only run valid pages if no problems with the page set or individual pages.
return True
def _WaitForThermalThrottlingIfNeeded(platform): def _WaitForThermalThrottlingIfNeeded(platform):
......
...@@ -9,9 +9,11 @@ import sys ...@@ -9,9 +9,11 @@ import sys
from telemetry import benchmark from telemetry import benchmark
from telemetry import user_story from telemetry import user_story
from telemetry.core import exceptions from telemetry.core import exceptions
from telemetry.page import page_set
from telemetry.page import page_test from telemetry.page import page_test
from telemetry.page import test_expectations from telemetry.page import test_expectations
from telemetry.results import results_options from telemetry.results import results_options
from unittest_data import test_simple_one_page_set
from telemetry.unittest_util import options_for_unittests from telemetry.unittest_util import options_for_unittests
from telemetry.unittest_util import system_stub from telemetry.unittest_util import system_stub
from telemetry.user_story import shared_user_story_state from telemetry.user_story import shared_user_story_state
...@@ -340,3 +342,37 @@ class UserStoryRunnerTest(unittest.TestCase): ...@@ -340,3 +342,37 @@ class UserStoryRunnerTest(unittest.TestCase):
self.assertIn('*RESULT metric: metric= [1,2,3,4] unit', contents) self.assertIn('*RESULT metric: metric= [1,2,3,4] unit', contents)
finally: finally:
sys.stdout = real_stdout sys.stdout = real_stdout
def testCheckArchives(self):
ps = page_set.PageSet()
ps.AddPageWithDefaultRunNavigate('http://www.testurl.com')
# Page set missing archive_data_file.
self.assertFalse(user_story_runner._CheckArchives(
ps.archive_data_file, ps.wpr_archive_info, ps.pages))
ps = page_set.PageSet(archive_data_file='missing_archive_data_file.json')
ps.AddPageWithDefaultRunNavigate('http://www.testurl.com')
# Page set missing json file specified in archive_data_file.
self.assertFalse(user_story_runner._CheckArchives(
ps.archive_data_file, ps.wpr_archive_info, ps.pages))
ps = page_set.PageSet(archive_data_file='../../unittest_data/test.json',
bucket=page_set.PUBLIC_BUCKET)
ps.AddPageWithDefaultRunNavigate('http://www.testurl.com')
# Page set with valid archive_data_file.
self.assertTrue(user_story_runner._CheckArchives(
ps.archive_data_file, ps.wpr_archive_info, ps.pages))
ps.AddPageWithDefaultRunNavigate('http://www.google.com')
# Page set with an archive_data_file which exists but is missing a page.
self.assertFalse(user_story_runner._CheckArchives(
ps.archive_data_file, ps.wpr_archive_info, ps.pages))
ps = page_set.PageSet(
archive_data_file='../../unittest_data/test_missing_wpr_file.json',
bucket=page_set.PUBLIC_BUCKET)
ps.AddPageWithDefaultRunNavigate('http://www.testurl.com')
ps.AddPageWithDefaultRunNavigate('http://www.google.com')
# Page set with an archive_data_file which exists and contains all pages
# but fails to find a wpr file.
self.assertFalse(user_story_runner._CheckArchives(
ps.archive_data_file, ps.wpr_archive_info, ps.pages))
{
"description": "Describes the Web Page Replay archives for a page set. Don't edit by hand! Use record_wpr for updating.",
"archives": {
"test_000.wpr": [
"http://www.testurl.com"
]
}
}
File needed for user_story_runner_unittests testCheckArchives.
6bd6f4b08b44abc206f68471c0444df156d0fd1a
\ No newline at end of file
{
"description": "Describes the Web Page Replay archives for a page set. Don't edit by hand! Use record_wpr for updating.",
"archives": {
"test_000.wpr": [
"http://www.testurl.com"
],
"test_missing_wpr_file.wpr": [
"http://www.google.com"
]
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment