Skip to content

Commit 2b597f3

Browse files
committed
Merge branch 'ls/test-must-fail-sigpipe'
Fix some racy client/server tests by treating SIGPIPE the same as a normal non-zero exit. * ls/test-must-fail-sigpipe: add "ok=sigpipe" to test_must_fail and use it to fix flaky tests implement test_might_fail using a refactored test_must_fail
2 parents b1cda70 + 8bf4bec commit 2b597f3

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

t/t5504-fetch-receive-strict.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test_expect_success 'push with receive.fsckobjects' '
100100
git config receive.fsckobjects true &&
101101
git config transfer.fsckobjects false
102102
) &&
103-
test_must_fail git push --porcelain dst master:refs/heads/test >act &&
103+
test_must_fail ok=sigpipe git push --porcelain dst master:refs/heads/test >act &&
104104
test_cmp exp act
105105
'
106106

@@ -111,8 +111,7 @@ test_expect_success 'push with transfer.fsckobjects' '
111111
cd dst &&
112112
git config transfer.fsckobjects true
113113
) &&
114-
test_must_fail git push --porcelain dst master:refs/heads/test >act &&
115-
test_cmp exp act
114+
test_must_fail ok=sigpipe git push --porcelain dst master:refs/heads/test >act
116115
'
117116

118117
cat >bogus-commit <<\EOF

t/t5516-fetch-push.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,15 +1162,15 @@ do
11621162
mk_empty shallow &&
11631163
(
11641164
cd shallow &&
1165-
test_must_fail git fetch ../testrepo/.git $SHA1_3 &&
1166-
test_must_fail git fetch ../testrepo/.git $SHA1_1 &&
1165+
test_must_fail ok=sigpipe git fetch ../testrepo/.git $SHA1_3 &&
1166+
test_must_fail ok=sigpipe git fetch ../testrepo/.git $SHA1_1 &&
11671167
git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
11681168
git fetch ../testrepo/.git $SHA1_1 &&
11691169
git cat-file commit $SHA1_1 &&
11701170
test_must_fail git cat-file commit $SHA1_2 &&
11711171
git fetch ../testrepo/.git $SHA1_2 &&
11721172
git cat-file commit $SHA1_2 &&
1173-
test_must_fail git fetch ../testrepo/.git $SHA1_3
1173+
test_must_fail ok=sigpipe git fetch ../testrepo/.git $SHA1_3
11741174
)
11751175
'
11761176
done

t/test-lib-functions.sh

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,21 @@ test_line_count () {
569569
fi
570570
}
571571

572+
# Returns success if a comma separated string of keywords ($1) contains a
573+
# given keyword ($2).
574+
# Examples:
575+
# `list_contains "foo,bar" bar` returns 0
576+
# `list_contains "foo" bar` returns 1
577+
578+
list_contains () {
579+
case ",$1," in
580+
*,$2,*)
581+
return 0
582+
;;
583+
esac
584+
return 1
585+
}
586+
572587
# This is not among top-level (test_expect_success | test_expect_failure)
573588
# but is a prefix that can be used in the test script, like:
574589
#
@@ -582,18 +597,34 @@ test_line_count () {
582597
# the failure could be due to a segv. We want a controlled failure.
583598

584599
test_must_fail () {
600+
case "$1" in
601+
ok=*)
602+
_test_ok=${1#ok=}
603+
shift
604+
;;
605+
*)
606+
_test_ok=
607+
;;
608+
esac
585609
"$@"
586610
exit_code=$?
587-
if test $exit_code = 0; then
611+
if test $exit_code -eq 0 && ! list_contains "$_test_ok" success
612+
then
588613
echo >&2 "test_must_fail: command succeeded: $*"
589614
return 1
590-
elif test $exit_code -gt 129 && test $exit_code -le 192; then
615+
elif test $exit_code -eq 141 && list_contains "$_test_ok" sigpipe
616+
then
617+
return 0
618+
elif test $exit_code -gt 129 && test $exit_code -le 192
619+
then
591620
echo >&2 "test_must_fail: died by signal: $*"
592621
return 1
593-
elif test $exit_code = 127; then
622+
elif test $exit_code -eq 127
623+
then
594624
echo >&2 "test_must_fail: command not found: $*"
595625
return 1
596-
elif test $exit_code = 126; then
626+
elif test $exit_code -eq 126
627+
then
597628
echo >&2 "test_must_fail: valgrind error: $*"
598629
return 1
599630
fi
@@ -612,16 +643,7 @@ test_must_fail () {
612643
# because we want to notice if it fails due to segv.
613644

614645
test_might_fail () {
615-
"$@"
616-
exit_code=$?
617-
if test $exit_code -gt 129 && test $exit_code -le 192; then
618-
echo >&2 "test_might_fail: died by signal: $*"
619-
return 1
620-
elif test $exit_code = 127; then
621-
echo >&2 "test_might_fail: command not found: $*"
622-
return 1
623-
fi
624-
return 0
646+
test_must_fail ok=success "$@"
625647
}
626648

627649
# Similar to test_must_fail and test_might_fail, but check that a

0 commit comments

Comments
 (0)