Skip to content

Commit c27efe6

Browse files
authored
further reducing flakiness in utils/check_bad_commit.py (#41658) (#41815)
* 111 * fix * fix * fix --------- Co-authored-by: ydshieh <[email protected]>
1 parent 8c29184 commit c27efe6

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

utils/check_bad_commit.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ def is_bad_commit(target_test, commit):
9797
# Restore to original commit
9898
repo.git.checkout(original_head)
9999

100-
return result.returncode != 0
100+
n_passed = 0
101+
o = re.findall(r"====.* (\d+) passed", result.stdout)
102+
if len(o) > 0:
103+
n_passed = int(o[0])
104+
105+
n_failed = 0
106+
o = re.findall(r"====.* (\d+) failed", result.stdout)
107+
if len(o) > 0:
108+
n_failed = int(o[0])
109+
110+
return result.returncode != 0, n_failed, n_passed
101111

102112

103113
def find_bad_commit(target_test, start_commit, end_commit):
@@ -113,7 +123,8 @@ def find_bad_commit(target_test, start_commit, end_commit):
113123
"""
114124

115125
# check if `end_commit` fails the test
116-
failed_before = is_bad_commit(target_test, end_commit)
126+
# (we only need one failure to conclude the test is flaky on the previous run with `end_commit`)
127+
failed_before, _, _ = is_bad_commit(target_test, end_commit)
117128
if failed_before:
118129
return (
119130
None,
@@ -130,8 +141,9 @@ def find_bad_commit(target_test, start_commit, end_commit):
130141

131142
# Now, we are (almost) sure `target_test` is not failing at `end_commit`
132143
# check if `start_commit` fail the test
133-
failed_now = is_bad_commit(target_test, start_commit)
134-
if not failed_now:
144+
# **IMPORTANT** we only need one pass to conclude the test is flaky on the current run with `start_commit`!
145+
_, n_failed, n_passed = is_bad_commit(target_test, start_commit)
146+
if n_passed > 0:
135147
# failed on CI run, but not reproducible here --> don't report
136148
return None, f"flaky: test fails on the current CI run (commit: {start_commit}) but passes during the check."
137149

@@ -194,12 +206,13 @@ def get_commit_info(commit):
194206
if pr_for_commit["merged_by"] is not None:
195207
merged_author = pr_for_commit["merged_by"]["login"]
196208

209+
url = f"https://api.github.com/repos/huggingface/transformers/commits/{commit}"
210+
commit_info = requests.get(url).json()
211+
parent = commit_info["parents"][0]["sha"]
197212
if author is None:
198-
url = f"https://api.github.com/repos/huggingface/transformers/commits/{commit}"
199-
commit_info = requests.get(url).json()
200213
author = commit_info["author"]["login"]
201214

202-
return {"commit": commit, "pr_number": pr_number, "author": author, "merged_by": merged_author}
215+
return {"commit": commit, "pr_number": pr_number, "author": author, "merged_by": merged_author, "parent": parent}
203216

204217

205218
if __name__ == "__main__":

0 commit comments

Comments
 (0)