Skip to content

Commit 76e27fb

Browse files
szedergitster
authored andcommitted
test-lib: make '--stress' more bisect-friendly
Let's suppose that a test somehow becomes flaky between 'master' and 'pu', and tends to fail within the first 50 repetitions when run with '--stress'. In such a case we could use 'git bisect' to find the culprit: if the test script fails with '--stress', then the commit is definitely bad, but if it survives, say, 300 repetitions, then we could consider it good with reasonable confidence. Unfortunately, all this could only be done manually, because '--stress' would run the test script repeatedly for all eternity on a good commit, and it would exit with success even when it found a failure on a bad commit. So let's make '--stress' usable with 'git bisect run': - Make it exit with failure if a failure is found. - Add the '--stress-limit=<N>' option to repeat the test script at most N times in each of the parallel jobs, and exit with success when the limit is reached. And then we could simply run something like: $ git bisect start origin/pu master $ git bisect run sh -c 'make && cd t && ./t1234-foo.sh --stress --stress-limit=300' Sure, as a brand new feature it won't be any useful right now, but in a release or three most cooking topics will already contain this, so we could automatically bisect at least newly introduced flakiness. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d1e3 commit 76e27fb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

t/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ appropriately before running "make".
202202
'.stress-<nr>' suffix, and the trash directory of the failed
203203
test job is renamed to end with a '.stress-failed' suffix.
204204

205+
--stress-limit=<N>::
206+
When combined with --stress run the test script repeatedly
207+
this many times in each of the parallel jobs or until one of
208+
them fails, whichever comes first.
209+
205210
You can also set the GIT_TEST_INSTALLED environment variable to
206211
the bindir of an existing git installation to test that installation.
207212
You still need to have built this git sandbox, from which various

t/test-lib.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ do
152152
;;
153153
esac
154154
;;
155+
--stress-limit=*)
156+
stress_limit=${opt#--*=}
157+
case "$stress_limit" in
158+
*[^0-9]*|0*|"")
159+
echo "error: --stress-limit=<N> requires the number of repetitions" >&2
160+
exit 1
161+
;;
162+
*) # Good.
163+
;;
164+
esac
165+
;;
155166
*)
156167
echo "error: unknown test option '$opt'" >&2; exit 1 ;;
157168
esac
@@ -237,8 +248,10 @@ then
237248
exit 1
238249
' TERM INT
239250

240-
cnt=0
241-
while ! test -e "$stressfail"
251+
cnt=1
252+
while ! test -e "$stressfail" &&
253+
{ test -z "$stress_limit" ||
254+
test $cnt -le $stress_limit ; }
242255
do
243256
$TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 &
244257
test_pid=$!
@@ -261,6 +274,7 @@ then
261274

262275
if test -f "$stressfail"
263276
then
277+
stress_exit=1
264278
echo "Log(s) of failed test run(s):"
265279
for failed_job_nr in $(sort -n "$stressfail")
266280
do

0 commit comments

Comments
 (0)