Skip to content

Commit

Permalink
Fail if the Go test command has not been executed properly, even with…
Browse files Browse the repository at this point in the history
… TestWasher (#26181)
  • Loading branch information
KevinFairise2 authored Jun 5, 2024
1 parent f5c21a0 commit 30ff86b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
20 changes: 16 additions & 4 deletions tasks/testwasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ def __init__(

self.parse_flaky_file()

def get_non_flaky_failing_tests(self, module_path):
def get_non_flaky_failing_tests(self, failing_tests: dict, flaky_marked_tests: dict):
"""
Parse the test output json file and compute the failing tests and the one known flaky
"""

failing_tests, flaky_marked_tests = self.parse_test_results(module_path)

all_known_flakes = self.merge_known_flakes(flaky_marked_tests)
non_flaky_failing_tests = defaultdict(set)

Expand Down Expand Up @@ -92,14 +90,28 @@ def process_module_results(self, module_results: list[ModuleTestResult]):

should_succeed = True
failed_tests = []
failed_command_modules = []
for module_result in module_results:
if non_flaky_failing_tests := self.get_non_flaky_failing_tests(module_result.path):
failing_tests, flaky_marked_tests = self.parse_test_results(module_result.path)
non_flaky_failing_tests = self.get_non_flaky_failing_tests(
failing_tests=failing_tests, flaky_marked_tests=flaky_marked_tests
)
if (
not failing_tests and module_result.failed
): # In this case the Go test command failed on one of the modules but no test failed, it means that the test command itself failed (build errors,...)
should_succeed = False
failed_command_modules.append(module_result.path)
if non_flaky_failing_tests:
should_succeed = False
for package, tests in non_flaky_failing_tests.items():
failed_tests.extend(f"- {package} {test}" for test in tests)
if failed_tests:
print("The test command failed, the following tests failed and are not supposed to be flaky:")
print("\n".join(sorted(failed_tests)))
if failed_command_modules:
print("The test command failed, before test execution on the following modules:")
print("\n".join(sorted(failed_command_modules)))
print("Please check the job logs for more information")

return should_succeed

Expand Down
20 changes: 16 additions & 4 deletions tasks/unit-tests/testwasher_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def test_flaky_marked_failing_test(self):
flakes_file_path="tasks/unit-tests/testdata/flakes_2.yaml",
)
module_path = "tasks/unit-tests/testdata"
non_flaky_failing_tests = test_washer_1.get_non_flaky_failing_tests(module_path)
failing_tests, marked_flaky_tests = test_washer_1.parse_test_results(module_path)
non_flaky_failing_tests = test_washer_1.get_non_flaky_failing_tests(
failing_tests=failing_tests, flaky_marked_tests=marked_flaky_tests
)
self.assertEqual(non_flaky_failing_tests, {})

def test_flakes_file_failing_test(self):
Expand All @@ -19,7 +22,10 @@ def test_flakes_file_failing_test(self):
flakes_file_path="tasks/unit-tests/testdata/flakes_1.yaml",
)
module_path = "tasks/unit-tests/testdata"
non_flaky_failing_tests = test_washer_2.get_non_flaky_failing_tests(module_path)
failing_tests, marked_flaky_tests = test_washer_2.parse_test_results(module_path)
non_flaky_failing_tests = test_washer_2.get_non_flaky_failing_tests(
failing_tests=failing_tests, flaky_marked_tests=marked_flaky_tests
)
self.assertEqual(non_flaky_failing_tests, {})

def test_should_fail_failing_tests(self):
Expand All @@ -28,7 +34,10 @@ def test_should_fail_failing_tests(self):
flakes_file_path="tasks/unit-tests/testdata/flakes_2.yaml",
)
module_path = "tasks/unit-tests/testdata"
non_flaky_failing_tests = test_washer_3.get_non_flaky_failing_tests(module_path)
failing_tests, marked_flaky_tests = test_washer_3.parse_test_results(module_path)
non_flaky_failing_tests = test_washer_3.get_non_flaky_failing_tests(
failing_tests=failing_tests, flaky_marked_tests=marked_flaky_tests
)
self.assertEqual(non_flaky_failing_tests, {"github.com/DataDog/datadog-agent/pkg/gohai": {"TestGetPayload"}})

def test_should_mark_parent_flaky(self):
Expand All @@ -37,7 +46,10 @@ def test_should_mark_parent_flaky(self):
flakes_file_path="tasks/unit-tests/testdata/flakes_2.yaml",
)
module_path = "tasks/unit-tests/testdata"
non_flaky_failing_tests = test_washer.get_non_flaky_failing_tests(module_path)
failing_tests, marked_flaky_tests = test_washer.parse_test_results(module_path)
non_flaky_failing_tests = test_washer.get_non_flaky_failing_tests(
failing_tests=failing_tests, flaky_marked_tests=marked_flaky_tests
)
self.assertEqual(
non_flaky_failing_tests,
{"github.com/DataDog/datadog-agent/test/new-e2e/tests/containers": {"TestEKSSuite/TestMemory"}},
Expand Down

0 comments on commit 30ff86b

Please sign in to comment.