Skip to content

Commit abe6d2c

Browse files
tcl3gmta
authored andcommitted
CI: Add a PR CI step to check new and modified tests for flakiness
1 parent 6ebf9c5 commit abe6d2c

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

.github/workflows/lagom-template.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ jobs:
201201
--load="module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulse-native" \
202202
--load="module-null-sink sink_name=virtual_sink"
203203
204+
- name: Check new tests for flakiness
205+
if: ${{ github.event_name == 'pull_request' && inputs.build_preset == 'Sanitizer' && (inputs.os_name == 'Linux' || inputs.os_name == 'macOS') }}
206+
timeout-minutes: 30
207+
working-directory: ${{ github.workspace }}
208+
shell: bash
209+
run: |
210+
git fetch --no-tags --depth=1 origin ${{ github.event.pull_request.base.sha }}
211+
"${{ env.pythonLocation }}/bin/python" Meta/check-test-flakiness.py \
212+
--test-web-binary Build/bin/test-web \
213+
--base-ref ${{ github.event.pull_request.base.sha }} \
214+
--deadline-seconds 1200 \
215+
--python-executable "${{ env.pythonLocation }}/bin/python" \
216+
| tee -a "$GITHUB_STEP_SUMMARY"
217+
204218
- name: Test
205219
if: ${{ inputs.build_preset == 'Sanitizer' }}
206220
working-directory: ${{ github.workspace }}

Meta/check-test-flakiness.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ def parse_dry_run_output(output):
8282
return tests
8383

8484

85+
def changed_files_in_test_root(repo_root, base_ref):
86+
output = run_git(repo_root, "diff", "--name-only", base_ref, "--", TEST_ROOT_RELATIVE.as_posix())
87+
prefix = TEST_ROOT_RELATIVE.as_posix() + "/"
88+
return [line[len(prefix) :] for line in output.splitlines() if line.startswith(prefix)]
89+
90+
91+
def find_modified_tests(repo_root, base_ref, pr_tests):
92+
tests_by_input_path = {}
93+
for test in pr_tests:
94+
tests_by_input_path.setdefault(test.partition("?")[0], set()).add(test)
95+
96+
modified_tests = set()
97+
for relative_path in changed_files_in_test_root(repo_root, base_ref):
98+
modified_tests.update(tests_by_input_path.get(relative_path, ()))
99+
return modified_tests
100+
101+
85102
def dry_run_tests(test_web_binary, test_root, python_executable, results_dir):
86103
command = [
87104
str(test_web_binary),
@@ -115,7 +132,11 @@ def discover_candidates(args, repo_root, test_web_binary, base_worktree, scratch
115132
base_tests = dry_run_tests(test_web_binary, base_test_root, args.python_executable, scratch_dir / "dry-run-base")
116133
log(f" {len(base_tests)} tests discovered.")
117134

118-
return sorted(pr_tests - base_tests)
135+
new_tests = pr_tests - base_tests
136+
modified_tests = find_modified_tests(repo_root, args.base_ref, pr_tests) - new_tests
137+
log(f" {len(new_tests)} new and {len(modified_tests)} modified test(s) found.")
138+
139+
return sorted(new_tests) + sorted(modified_tests)
119140

120141

121142
def parse_concurrency_levels(spec):
@@ -288,7 +309,7 @@ def main(argv):
288309
cleanup_worktree(repo_root, base_worktree_path, scratch_dir)
289310

290311
if not candidates:
291-
log("No new tests: nothing to check.")
312+
log("No new or modified tests: nothing to check.")
292313
return 0
293314

294315
log(f"{len(candidates)} candidate test(s) to check at parallelism levels {levels}.")

0 commit comments

Comments
 (0)