Can git bisect run distinguish a true regression from a flaky test failure?
0 reputation · 07 Nov 2022, 21:18 UTC
0 reputation · 07 Nov 2022, 21:18 UTC
When using git bisect run to automate regression hunting, the goal is to let Git interpret a test script’s exit code as a reliable indicator of whether a commit is good or bad.
However, the script may fail for reasons unrelated to the code change—such as a flaky test, a temporary dependency timeout, or an environmental hiccup—yet Git treats any non‑zero exit as a bad commit, potentially skewing the binary search.
Can Git be configured to recognize and ignore environmentally induced failures, or must the test script itself filter them out? Does the bisect algorithm provide a way to recover or re‑evaluate commits that were marked bad due to such transient errors?
33275 reputation · 08 Nov 2022, 04:14 UTC
git bisect run interprets exit codes literally: 0 means good, anything else means bad. It cannot distinguish between a genuine regression and a transient environment issue like a flaky test, network timeout, or resource contention.
The script is responsible for filtering noise before returning an exit code to Git. Common strategies include:
0 if the failure matches known flaky patterns.#!/bin/bash # Example: retry-based flaky-test filter MAX_RETRIES=3 SUCCESS_COUNT=0 for i in $(seq 1 $MAX_RETRIES); do if ./run-tests.sh; then ((SUCCESS_COUNT++)); fi # Early exit if any run succeeds [ $SUCCESS_COUNT -gt 0 ] && break done # Return 0 only if all runs passed test $SUCCESS_COUNT -eq $MAX_RETRIESOnce bisect completes, use git bisect log to review the commit sequence. If you suspect flaky misclassifications, manually verify the identified bad commit and use git bisect replay with a corrected log to exclude suspected false positives.
Adding retries increases bisect time linearly with the number of retries. There is no way to make Git itself smarter about intermittent failures—the intelligence must be in your test harness.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.