Commit a0aac3cb authored by machenbach's avatar machenbach Committed by Commit bot

[test] Fix deterministic test shards.

Test case objects were sorted without key function, resulting
in random sort order. On sharded builds, the shards are
determined by the sort order and rely on a deterministic
sorting. This led to random cctest and unittest cases being
dropped or executed twice on sharded testers.

TBR=jkummerow@chromium.org, hablich@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#35151}
parent 799eea17
......@@ -58,7 +58,7 @@ class CcTestSuite(testsuite.TestSuite):
for test_desc in output.stdout.strip().split():
test = testcase.TestCase(self, test_desc)
tests.append(test)
tests.sort()
tests.sort(key=lambda t: t.path)
return tests
def GetFlagsForTestCase(self, testcase, context):
......
......@@ -316,7 +316,7 @@ class GoogleTestSuite(TestSuite):
elif test_case and test_desc:
test = testcase.TestCase(self, test_case + test_desc)
tests.append(test)
tests.sort()
tests.sort(key=lambda t: t.path)
return tests
def GetFlagsForTestCase(self, testcase, context):
......
......@@ -100,3 +100,11 @@ class TestCase(object):
send the name only and retrieve a process-local suite later.
"""
return dict(self.__dict__, suite=self.suite.name)
def __cmp__(self, other):
# Make sure that test cases are sorted correctly if sorted without
# key function. But using a key function is preferred for speed.
return cmp(
(self.suite.name, self.path, self.flags),
(other.suite.name, other.path, other.flags),
)
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