Skip to content

Commit

Permalink
[Android] Prepare the test runner for @RetryOnFailure.
Browse files Browse the repository at this point in the history
BUG=619055

Review-Url: https://codereview.chromium.org/2099323002
Cr-Commit-Position: refs/heads/master@{#404774}
  • Loading branch information
jbudorick authored and Commit bot committed Jul 12, 2016
1 parent c8de951 commit ec256fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

// Note this annotation may not do anything yet. Check crbug.com/622451
// Note this annotation may not do anything yet. Check crbug.com/619055
// for latest status.
/**
* Mark a test as flaky and should be retried on failure. The test is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ def name_and_timeout(t):
'*'))
return results

#override
def _ShouldRetry(self, test):
if 'RetryOnFailure' in test.get('annotations', {}):
return True

# TODO(jbudorick): Remove this log message and switch the return value to
# False after tests have been annotated with @RetryOnFailure.
# See crbug.com/619055 for more details.
logging.warning('Default retries are being phased out. crbug.com/619055')
return True

#override
def _ShouldShard(self):
return True
Expand Down
18 changes: 12 additions & 6 deletions build/android/pylib/local/device/local_device_test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def stop_tests(_signum, _frame):

def _GetTestsToRetry(self, tests, try_results):

def is_failure(test_result):
def is_failure_result(test_result):
return (
test_result is None
or test_result.GetType() not in (
Expand All @@ -185,15 +185,17 @@ def is_failure(test_result):

all_test_results = {r.GetName(): r for r in try_results.GetAll()}

def should_retry(name):
def test_failed(name):
# When specifying a test filter, names can contain trailing wildcards.
# See local_device_gtest_run._ExtractTestsFromFilter()
if name.endswith('*'):
return any(fnmatch.fnmatch(n, name) and is_failure(t)
return any(fnmatch.fnmatch(n, name) and is_failure_result(t)
for n, t in all_test_results.iteritems())
return is_failure(all_test_results.get(name))
return is_failure_result(all_test_results.get(name))

return [t for t in tests if should_retry(self._GetUniqueTestName(t))]
failed_tests = (t for t in tests if test_failed(self._GetUniqueTestName(t)))

return [t for t in failed_tests if self._ShouldRetry(t)]

def GetTool(self, device):
if not str(device) in self._tools:
Expand All @@ -204,10 +206,14 @@ def GetTool(self, device):
def _CreateShards(self, tests):
raise NotImplementedError

# pylint: disable=no-self-use
def _GetUniqueTestName(self, test):
# pylint: disable=no-self-use
return test

def _ShouldRetry(self, test):
# pylint: disable=no-self-use,unused-argument
return True

def _GetTests(self):
raise NotImplementedError

Expand Down

0 comments on commit ec256fa

Please sign in to comment.