0

Telemetry: Move TimeoutException from util module to exceptions module.

This change helps move the Telemetry framework towards saner exception
handling.

BUG=460625

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

Cr-Commit-Position: refs/heads/master@{#318349}
This commit is contained in:
erikchen
2015-02-26 16:34:39 -08:00
committed by Commit bot
parent c89ecfaa34
commit 68c881e69b
26 changed files with 52 additions and 48 deletions

@ -72,7 +72,7 @@ class _ContextLostValidator(page_test.PageTest):
util.WaitFor(lambda: tab.EvaluateJavaScript(
'window.domAutomationController._finished'), wait_timeout)
return True
except util.TimeoutException:
except exceptions.TimeoutException:
return False
if page.kill_gpu_process:

@ -5,7 +5,7 @@
import sys
import time
from telemetry.core.util import TimeoutException
from telemetry.core import exceptions
from telemetry.page import page_test
from telemetry.value import scalar
@ -31,7 +31,7 @@ class RasterizeAndRecordMicro(page_test.PageTest):
def ValidateAndMeasurePage(self, page, tab, results):
try:
tab.WaitForDocumentReadyStateToBeComplete()
except TimeoutException:
except exceptions.TimeoutException:
pass
time.sleep(self._start_wait_time)

@ -7,7 +7,7 @@ import logging
from metrics import Metric
from telemetry.core import util
from telemetry.core import exceptions
from telemetry.value import histogram_util
from telemetry.value import scalar
@ -74,7 +74,7 @@ class StartupMetric(Metric):
int(result['load_start_ms']),
int(result['load_duration_ms']),
int(perf_timing['requestStart'])))
except util.TimeoutException:
except exceptions.TimeoutException:
# Low memory Android devices may not be able to load more than
# one tab at a time, so may timeout when the test attempts to
# access a background tab. Ignore these tabs.

@ -7,7 +7,6 @@ from telemetry.core import browser_finder
from telemetry.core import browser_finder_exceptions
from telemetry.core import exceptions
from telemetry.core import platform
from telemetry.core import util
from telemetry.core.backends.chrome_inspector import devtools_http
@ -240,7 +239,7 @@ class FastNavigationProfileExtender(object):
try:
tab.WaitForDocumentReadyStateToBeComplete(seconds_to_wait)
except util.TimeoutException:
except exceptions.TimeoutException:
# Ignore time outs.
pass
except (exceptions.DevtoolsTargetCrashException,

@ -189,7 +189,7 @@ class ChromeBrowserBackend(browser_backend.BrowserBackend):
""" Wait for browser to come up. """
try:
util.WaitFor(self.HasBrowserFinishedLaunching, timeout=30)
except (util.TimeoutException, exceptions.ProcessGoneException) as e:
except (exceptions.TimeoutException, exceptions.ProcessGoneException) as e:
if not self.IsBrowserRunning():
raise exceptions.BrowserGoneException(self.browser, e)
raise exceptions.BrowserConnectionGoneException(self.browser, e)
@ -204,7 +204,7 @@ class ChromeBrowserBackend(browser_backend.BrowserBackend):
'Waiting for extensions required devtool client to be initiated first')
try:
util.WaitFor(self._AllExtensionsLoaded, timeout=60)
except util.TimeoutException:
except exceptions.TimeoutException:
logging.error('ExtensionsToLoad: ' +
repr([e.extension_id for e in self._extensions_to_load]))
logging.error('Extension list: ' +

@ -143,7 +143,7 @@ class CrOSBrowserBackend(chrome_browser_backend.ChromeBrowserBackend):
else:
self.oobe.NavigateFakeLogin(self._username, self._password)
self._WaitForLogin()
except util.TimeoutException:
except exceptions.TimeoutException:
self._cri.TakeScreenShot('login-screen')
raise exceptions.LoginException('Timed out going through login screen')

@ -369,7 +369,7 @@ class DesktopBrowserBackend(chrome_browser_backend.ChromeBrowserBackend):
try:
util.WaitFor(lambda: not self.IsBrowserRunning(), timeout=5)
logging.info('Successfully shut down browser cooperatively')
except util.TimeoutException as e:
except exceptions.TimeoutException as e:
logging.warning('Failed to cooperatively shutdown. ' +
'Proceeding to terminate: ' + str(e))
@ -385,7 +385,7 @@ class DesktopBrowserBackend(chrome_browser_backend.ChromeBrowserBackend):
try:
util.WaitFor(lambda: not self.IsBrowserRunning(), timeout=5)
self._proc = None
except util.TimeoutException:
except exceptions.TimeoutException:
logging.warning('Failed to gracefully shutdown. Proceeding to kill.')
# Shutdown aggressively if the above failed or if the profile is temporary.

@ -8,6 +8,7 @@ import logging
import re
import urllib2
from telemetry.core import exceptions
from telemetry.core import util
from telemetry.core.backends.chrome import chrome_browser_backend
from telemetry.core.backends.chrome import system_info_backend
@ -90,7 +91,7 @@ class IosBrowserBackend(chrome_browser_backend.ChromeBrowserBackend):
# Retry a few times since it can take a few seconds for this API to be
# ready, if ios_webkit_debug_proxy is just launched.
data = util.WaitFor(GetData, 5)
except util.TimeoutException as e:
except exceptions.TimeoutException as e:
logging.debug('Timeout retrieving data from iOS device')
logging.debug(e)
return []

@ -44,7 +44,7 @@ class InspectorBackend(object):
logging.debug('InspectorBackend._Connect() to %s', self.debugger_url)
try:
self._websocket.Connect(self.debugger_url)
except (websocket.WebSocketException, util.TimeoutException) as e:
except (websocket.WebSocketException, exceptions.TimeoutException) as e:
raise InspectorException(e.msg)
self._console = inspector_console.InspectorConsole(self._websocket)

@ -3,7 +3,7 @@
# found in the LICENSE file.
import logging
from telemetry.core import util
from telemetry.core import exceptions
class InspectorNetworkException(Exception):
@ -188,7 +188,7 @@ class InspectorNetwork(object):
'requestId': request_id,
}
}, timeout)
except util.TimeoutException:
except exceptions.TimeoutException:
logging.warning('Timeout during fetching body for %s' % request_id)
return None, False
if 'error' in res:

@ -4,7 +4,6 @@
import sys
import time
from telemetry.core import util
from telemetry.image_processing import image_util

@ -3,7 +3,7 @@
# found in the LICENSE file.
import logging
from telemetry.core import util
from telemetry.core import exceptions
class FormBasedCredentialsBackend(object):
@ -111,7 +111,7 @@ class FormBasedCredentialsBackend(object):
self._logged_in = True
return True
except util.TimeoutException:
except exceptions.TimeoutException:
logging.warning('Timed out while loading: %s', url)
return False

@ -7,6 +7,10 @@ class PlatformError(Exception):
""" Represents an exception thrown when constructing platform. """
class TimeoutException(Exception):
pass
class AppCrashException(Exception):
def __init__(self, app=None, msg=''):
super(AppCrashException, self).__init__(msg)

@ -6,6 +6,7 @@ import contextlib
import logging
import socket
from telemetry.core import exceptions
from telemetry.core import forwarders
from telemetry.core import util
@ -63,7 +64,7 @@ class DoNothingForwarder(forwarders.Forwarder):
logging.debug(
'Connection test succeeded for %s: %s:%d',
protocol.upper(), self.host_ip, local_port)
except util.TimeoutException:
except exceptions.TimeoutException:
raise ConnectionError(
'Unable to connect to %s address: %s:%d',
protocol.upper(), self.host_ip, local_port)

@ -4,8 +4,8 @@
import unittest
from telemetry.core import exceptions
from telemetry.core import forwarders
from telemetry.core import util
from telemetry.core.forwarders import do_nothing_forwarder
@ -24,7 +24,7 @@ class TestErrorDoNothingForwarder(do_nothing_forwarder.DoNothingForwarder):
"""Simulate a connection error."""
def _WaitForConnectionEstablished(self, address, timeout):
raise util.TimeoutException
raise exceptions.TimeoutException
class CheckPortPairsTest(unittest.TestCase):

@ -10,9 +10,7 @@ import socket
import sys
import time
class TimeoutException(Exception):
pass
from telemetry.core import exceptions
def GetBaseDir():
@ -80,8 +78,8 @@ def WaitFor(condition, timeout):
elapsed_time = now - start_time
last_output_elapsed_time = now - last_output_time
if elapsed_time > timeout:
raise TimeoutException('Timed out while waiting %ds for %s.' %
(timeout, GetConditionString()))
raise exceptions.TimeoutException('Timed out while waiting %ds for %s.' %
(timeout, GetConditionString()))
if last_output_elapsed_time > output_interval:
logging.info('Continuing to wait %ds for %s. Elapsed: %ds.',
timeout, GetConditionString(), elapsed_time)

@ -6,6 +6,7 @@ import shutil
import tempfile
import unittest
from telemetry.core import exceptions
from telemetry.core import util
@ -18,7 +19,8 @@ class TestWait(unittest.TestCase):
def testTimeout(self):
def test():
return False
self.assertRaises(util.TimeoutException, lambda: util.WaitFor(test, 0.1))
self.assertRaises(exceptions.TimeoutException,
lambda: util.WaitFor(test, 0.1))
def testCallable(self):
"""Test methods and anonymous functions, functions are tested elsewhere."""

@ -4,6 +4,7 @@
import os
from telemetry.core import exceptions
from telemetry.core import util
DEFAULT_WEB_CONTENTS_TIMEOUT = 90
@ -43,16 +44,16 @@ class WebContents(object):
def IsJavaScriptExpressionTrue():
try:
return bool(self.EvaluateJavaScript(expr))
except util.TimeoutException:
except exceptions.TimeoutException:
# If the main thread is busy for longer than Evaluate's timeout, we
# may time out here early. Instead, we want to wait for the full
# timeout of this method.
return False
try:
util.WaitFor(IsJavaScriptExpressionTrue, timeout)
except util.TimeoutException as e:
except exceptions.TimeoutException as e:
# Try to make timeouts a little more actionable by dumping |this|.
raise util.TimeoutException(e.message + self.EvaluateJavaScript("""
raise exceptions.TimeoutException(e.message + self.EvaluateJavaScript("""
(function() {
var error = '\\n\\nJavaScript |this|:\\n';
for (name in this) {

@ -12,6 +12,7 @@ import subprocess
import sys
import urllib
from telemetry.core import exceptions
from telemetry.core import util
_REPLAY_DIR = os.path.join(
@ -203,7 +204,7 @@ class ReplayServer(object):
self._started_ports['https'],
self._started_ports.get('dns'), # None if unused
)
except util.TimeoutException:
except exceptions.TimeoutException:
raise ReplayNotStartedError(
'Web Page Replay failed to start. Log output:\n%s' %
''.join(self._LogLines()))
@ -223,7 +224,7 @@ class ReplayServer(object):
try:
util.WaitFor(lambda: self.replay_process.poll() is not None, 10)
except util.TimeoutException:
except exceptions.TimeoutException:
try:
# Use a SIGINT so that it can do graceful cleanup.
self.replay_process.send_signal(signal.SIGINT)

@ -4,7 +4,6 @@
from telemetry import decorators
from telemetry.core import exceptions
from telemetry.core import util
from telemetry.core.platform import tracing_category_filter
from telemetry.core.platform import tracing_options
from telemetry.page.actions import action_runner as action_runner_module
@ -158,7 +157,7 @@ class ActionRunnerTest(tab_test_case.TabTestCase):
action_runner.WaitForElement('#test1', timeout_in_seconds=0.2)
def WaitForElement():
action_runner.WaitForElement(text='oo', timeout_in_seconds=0.2)
self.assertRaises(util.TimeoutException, WaitForElement)
self.assertRaises(exceptions.TimeoutException, WaitForElement)
def testClickElement(self):
self.Navigate('page_with_clickables.html')

@ -3,7 +3,7 @@
# found in the LICENSE file.
from telemetry import decorators
from telemetry.core import util
from telemetry.core import exceptions
from telemetry.page.actions import loop
from telemetry.unittest_util import tab_test_case
@ -49,4 +49,4 @@ class LoopActionTest(tab_test_case.TabTestCase):
timeout_in_seconds=1)
action.WillRunAction(self._tab)
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
self.assertRaises(exceptions.TimeoutException, action.RunAction, self._tab)

@ -3,7 +3,7 @@
# found in the LICENSE file.
from telemetry import decorators
from telemetry.core import util
from telemetry.core import exceptions
from telemetry.page.actions import play
from telemetry.unittest_util import tab_test_case
@ -68,7 +68,7 @@ class PlayActionTest(tab_test_case.TabTestCase):
action.WillRunAction(self._tab)
self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""')
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
self.assertRaises(exceptions.TimeoutException, action.RunAction, self._tab)
@decorators.Disabled('android', 'linux') # crbug.com/418577
def testPlayWaitForEnded(self):
@ -105,6 +105,6 @@ class PlayActionTest(tab_test_case.TabTestCase):
# Assert video not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_ENDED_CHECK))
self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
self.assertRaises(exceptions.TimeoutException, action.RunAction, self._tab)
# Assert video did not end.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_ENDED_CHECK))

@ -3,7 +3,7 @@
# found in the LICENSE file.
from telemetry import decorators
from telemetry.core import util
from telemetry.core import exceptions
from telemetry.page.actions import seek
from telemetry.unittest_util import tab_test_case
@ -63,4 +63,4 @@ class SeekActionTest(tab_test_case.TabTestCase):
action.WillRunAction(self._tab)
self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""')
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
self.assertRaises(exceptions.TimeoutException, action.RunAction, self._tab)

@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from telemetry.core import util
from telemetry.core import exceptions
from telemetry.unittest_util import browser_test_case
@ -19,7 +19,7 @@ class TabTestCase(browser_test_case.BrowserTestCase):
self._tab = self._browser.tabs.New()
while len(self._browser.tabs) > 1:
self._browser.tabs[0].Close()
except util.TimeoutException:
except exceptions.TimeoutException:
self._RestartBrowser()
else:
self._RestartBrowser()

@ -12,7 +12,6 @@ import time
from telemetry import decorators
from telemetry import page as page_module
from telemetry.core import exceptions
from telemetry.core import util
from telemetry.core import wpr_modes
from telemetry.page import page_set as page_set_module
from telemetry.page import page_test
@ -98,8 +97,8 @@ def _RunUserStoryAndProcessErrorIfNeeded(expectations, user_story, results,
results.AddValue(skip_value)
return
state.RunUserStory(results)
except (page_test.Failure, util.TimeoutException, exceptions.LoginException,
exceptions.ProfilingException):
except (page_test.Failure, exceptions.TimeoutException,
exceptions.LoginException, exceptions.ProfilingException):
ProcessError()
except exceptions.AppCrashException:
ProcessError()

@ -61,7 +61,7 @@ class FindDependenciesTest(unittest.TestCase):
# util.WaitFor(gsutil_process.poll, timeout=0.5)
# self.assertEqual(gsutil_process.returncode, 0,
# msg='gsutil config failed.')
#except util.TimeoutException:
#except exceptions.TimeoutException:
# gsutil_process.terminate()
# gsutil_process.wait()
finally: