Skip to content

Instantly share code, notes, and snippets.

@kirr
Created February 27, 2018 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kirr/022c26a34ad8aeeddf6dc87e84ff3261 to your computer and use it in GitHub Desktop.
Save kirr/022c26a34ad8aeeddf6dc87e84ff3261 to your computer and use it in GitHub Desktop.
Telemetry changes. Add tests "timeout" decotator.
diff --git a/src/third_party/catapult/telemetry/telemetry/decorators.py b/src/third_party/catapult/telemetry/telemetry/decorators.py
index ecc97fb..1bbc5d69 100644
--- a/src/third_party/catapult/telemetry/telemetry/decorators.py
+++ b/src/third_party/catapult/telemetry/telemetry/decorators.py
@@ -220,6 +220,27 @@ def Isolated(*args):
return _Isolated
+def Timeout(timeout_sec):
+ def _Timeout(func):
+ if not isinstance(func, types.FunctionType):
+ func._test_timeout = timeout_sec
+ return func
+
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs): # pylint: disable=invalid-name
+ return func(*args, **kwargs)
+
+ wrapper._test_timeout = timeout_sec
+ return wrapper
+
+ assert isinstance(timeout_sec, (int, long, float)), type(timeout_sec)
+ return _Timeout
+
+
+def GetTestTimeout(test):
+ return getattr(test, '_test_timeout', None)
+
+
# TODO(nednguyen): Remove this and have call site just use ShouldSkip directly.
def IsEnabled(test, possible_browser):
"""Returns True iff |test| is enabled given the |possible_browser|.
diff --git a/src/third_party/catapult/telemetry/telemetry/internal/backends/chrome/tab_list_backend_unittest.py b/src/third_party/catapult/telemetry/telemetry/internal/backends/chrome/tab_list_backend_unittest.py
index e61bb6e..6f97040 100644
--- a/src/third_party/catapult/telemetry/telemetry/internal/backends/chrome/tab_list_backend_unittest.py
+++ b/src/third_party/catapult/telemetry/telemetry/internal/backends/chrome/tab_list_backend_unittest.py
@@ -34,6 +34,7 @@ class TabListBackendTest(tab_test_case.TabTestCase):
# https://github.com/catapult-project/catapult/issues/3099 (Android)
@decorators.Enabled('has tabs')
@decorators.Disabled('android')
+ @decorators.Timeout(240)
def testTabIdStableAfterTabCrash(self):
# Ensure that there are two tabs.
while len(self.tabs) < 2:
diff --git a/src/third_party/catapult/telemetry/telemetry/internal/browser/tab_unittest.py b/src/third_party/catapult/telemetry/telemetry/internal/browser/tab_unittest.py
index ad3599e..ad59086 100644
--- a/src/third_party/catapult/telemetry/telemetry/internal/browser/tab_unittest.py
+++ b/src/third_party/catapult/telemetry/telemetry/internal/browser/tab_unittest.py
@@ -63,6 +63,7 @@ class TabTest(tab_test_case.TabTestCase):
def testTabBrowserIsRightBrowser(self):
self.assertEquals(self._tab.browser, self._browser)
+ @decorators.Timeout(240)
def testRendererCrash(self):
self.assertRaises(exceptions.DevtoolsTargetCrashException,
lambda: self._tab.Navigate('chrome://crash',
diff --git a/src/third_party/catapult/telemetry/telemetry/testing/run_tests.py b/src/third_party/catapult/telemetry/telemetry/testing/run_tests.py
index c6fdca1..893b927 100644
--- a/src/third_party/catapult/telemetry/telemetry/testing/run_tests.py
+++ b/src/third_party/catapult/telemetry/telemetry/testing/run_tests.py
@@ -175,9 +175,13 @@ class RunTestsCommand(command_line.OptparseCommand):
else:
runner.args.jobs = max(int(args.jobs) // 2, 1)
+ # Workaround for using py_trace_event in unittests with process pool.
+ # See multiprocessing_shim.py.
+ os.environ['DISABLE_PYTRACE_MULTIPROCESSING_SHIM'] = '1'
if platform.GetOSName() == 'mac' and args.clear_keychain:
yandex_keychain_helper.RemoveBrowserKeychainItems()
+ runner.args.timeout = args.timeout
runner.args.skip = args.skip
runner.args.metadata = args.metadata
runner.args.passthrough = args.passthrough
@@ -231,6 +235,10 @@ def GetClassifier(args, possible_browser, gtest_filter=None):
if (not args.positional_args
or _MatchesSelectedTest(
name, args.positional_args, args.exact_test_filter)):
+ method = getattr(
+ test, test._testMethodName) # pylint: disable=protected-access
+ timeout = decorators.GetTestTimeout(method)
+
# TODO(telemetry-team): Make sure that all telemetry unittest that invokes
# actual browser are subclasses of browser_test_case.BrowserTestCase
# (crbug.com/537428)
@@ -241,10 +249,12 @@ def GetClassifier(args, possible_browser, gtest_filter=None):
test_set.tests_to_skip.append(typ.TestInput(
name, msg='Skip the test because of gtest_filter.'))
else:
- test_set.parallel_tests.append(typ.TestInput(name))
+ test_set.parallel_tests.append(typ.TestInput(name, timeout=timeout))
def ClassifyTestWithBrowser(test_set, test):
name = test.id()
+ timeout = decorators.GetTestTimeout(test)
+
if _SkipMatch(name, args.skip):
test_set.tests_to_skip.append(
typ.TestInput(name, 'skipped because matched --skip'))
@@ -255,6 +265,8 @@ def GetClassifier(args, possible_browser, gtest_filter=None):
assert hasattr(test, '_testMethodName')
method = getattr(
test, test._testMethodName) # pylint: disable=protected-access
+ timeout = decorators.GetTestTimeout(method)
+
should_skip, reason = decorators.ShouldSkip(method, possible_browser)
if should_skip and not args.run_disabled_tests:
test_set.tests_to_skip.append(typ.TestInput(name, msg=reason))
@@ -262,9 +274,9 @@ def GetClassifier(args, possible_browser, gtest_filter=None):
test_set.tests_to_skip.append(typ.TestInput(
name, msg='Skip the test because of gtest_filter.'))
elif decorators.ShouldBeIsolated(method, possible_browser):
- test_set.isolated_tests.append(typ.TestInput(name))
+ test_set.isolated_tests.append(typ.TestInput(name, timeout=timeout))
else:
- test_set.parallel_tests.append(typ.TestInput(name))
+ test_set.parallel_tests.append(typ.TestInput(name, timeout=timeout))
if possible_browser:
return ClassifyTestWithBrowser
@@ -311,6 +323,7 @@ def _SetUpProcess(child, context): # pylint: disable=unused-argument
android_devices.sort(key=lambda device: device.name)
args.remote_platform_options.device = (
android_devices[child.worker_num-1].guid)
+ del os.environ['DISABLE_PYTRACE_MULTIPROCESSING_SHIM']
options_for_unittests.Push(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment