1
0
mirror of https://github.com/git/git synced 2024-07-04 16:48:40 +00:00

t5703: run all non-httpd-specific tests before sourcing 'lib-httpd.sh'

't5703-upload-pack-ref-in-want.sh' sources 'lib-httpd.sh' near the end
to run a couple of httpd-specific tests, but 'lib-httpd.sh' skips all
the rest of the test script if the dependencies for running httpd
tests are not fulfilled.  However, the last six tests in 't5703' are
not httpd-specific, but they are skipped as well when httpd tests
can't be run.

Move these six tests earlier in the test script, before 'lib-httpd.sh'
is sourced, so they will be run even when httpd tests aren't.  Note
that this is not merely a pure code movement, because the setup test
case for the httpd tests needed an additional 'rm -rf
"$LOCAL_PRISTINE"' to clean up a directory left behind by the moved
non-httpd-specific tests.

Also add a comment at the end of this test script to warn against
adding non-httpd-specific tests at the end, in the hope that it will
help prevent similar issues in the future.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
SZEDER Gábor 2019-08-01 17:53:08 +02:00 committed by Junio C Hamano
parent 12b1826609
commit 7f005b0f48

View File

@ -157,106 +157,6 @@ test_expect_success 'want-ref with ref we already have commit for' '
check_output
'
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
LOCAL_PRISTINE="$(pwd)/local_pristine"
test_expect_success 'setup repos for change-while-negotiating test' '
(
git init "$REPO" &&
cd "$REPO" &&
>.git/git-daemon-export-ok &&
test_commit m1 &&
git tag -d m1 &&
# Local repo with many commits (so that negotiation will take
# more than 1 request/response pair)
git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
cd "$LOCAL_PRISTINE" &&
git checkout -b side &&
test_commit_bulk --id=s 33 &&
# Add novel commits to upstream
git checkout master &&
cd "$REPO" &&
test_commit m2 &&
test_commit m3 &&
git tag -d m2 m3
) &&
git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_sed/repo" &&
git -C "$LOCAL_PRISTINE" config protocol.version 2
'
inconsistency () {
# Simulate that the server initially reports $2 as the ref
# corresponding to $1, and after that, $1 as the ref corresponding to
# $1. This corresponds to the real-life situation where the server's
# repository appears to change during negotiation, for example, when
# different servers in a load-balancing arrangement serve (stateless)
# RPCs during a single negotiation.
printf "s/%s/%s/" \
$(git -C "$REPO" rev-parse $1 | tr -d "\n") \
$(git -C "$REPO" rev-parse $2 | tr -d "\n") \
>"$HTTPD_ROOT_PATH/one-time-sed"
}
test_expect_success 'server is initially ahead - no ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant false &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master 1234567890123456789012345678901234567890 &&
test_must_fail git -C local fetch 2>err &&
test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
'
test_expect_success 'server is initially ahead - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master 1234567890123456789012345678901234567890 &&
git -C local fetch &&
git -C "$REPO" rev-parse --verify master >expected &&
git -C local rev-parse --verify refs/remotes/origin/master >actual &&
test_cmp expected actual
'
test_expect_success 'server is initially behind - no ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant false &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master "master^" &&
git -C local fetch &&
git -C "$REPO" rev-parse --verify "master^" >expected &&
git -C local rev-parse --verify refs/remotes/origin/master >actual &&
test_cmp expected actual
'
test_expect_success 'server is initially behind - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master "master^" &&
git -C local fetch &&
git -C "$REPO" rev-parse --verify "master" >expected &&
git -C local rev-parse --verify refs/remotes/origin/master >actual &&
test_cmp expected actual
'
test_expect_success 'server loses a ref - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
test_must_fail git -C local fetch 2>err &&
test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
'
REPO="$(pwd)/repo"
LOCAL_PRISTINE="$(pwd)/local_pristine"
@ -372,4 +272,108 @@ test_expect_success 'fetching with wildcard that matches multiple refs' '
grep "want-ref refs/heads/o/bar" log
'
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
LOCAL_PRISTINE="$(pwd)/local_pristine"
test_expect_success 'setup repos for change-while-negotiating test' '
(
git init "$REPO" &&
cd "$REPO" &&
>.git/git-daemon-export-ok &&
test_commit m1 &&
git tag -d m1 &&
# Local repo with many commits (so that negotiation will take
# more than 1 request/response pair)
rm -rf "$LOCAL_PRISTINE" &&
git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
cd "$LOCAL_PRISTINE" &&
git checkout -b side &&
test_commit_bulk --id=s 33 &&
# Add novel commits to upstream
git checkout master &&
cd "$REPO" &&
test_commit m2 &&
test_commit m3 &&
git tag -d m2 m3
) &&
git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_sed/repo" &&
git -C "$LOCAL_PRISTINE" config protocol.version 2
'
inconsistency () {
# Simulate that the server initially reports $2 as the ref
# corresponding to $1, and after that, $1 as the ref corresponding to
# $1. This corresponds to the real-life situation where the server's
# repository appears to change during negotiation, for example, when
# different servers in a load-balancing arrangement serve (stateless)
# RPCs during a single negotiation.
printf "s/%s/%s/" \
$(git -C "$REPO" rev-parse $1 | tr -d "\n") \
$(git -C "$REPO" rev-parse $2 | tr -d "\n") \
>"$HTTPD_ROOT_PATH/one-time-sed"
}
test_expect_success 'server is initially ahead - no ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant false &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master 1234567890123456789012345678901234567890 &&
test_must_fail git -C local fetch 2>err &&
test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
'
test_expect_success 'server is initially ahead - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master 1234567890123456789012345678901234567890 &&
git -C local fetch &&
git -C "$REPO" rev-parse --verify master >expected &&
git -C local rev-parse --verify refs/remotes/origin/master >actual &&
test_cmp expected actual
'
test_expect_success 'server is initially behind - no ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant false &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master "master^" &&
git -C local fetch &&
git -C "$REPO" rev-parse --verify "master^" >expected &&
git -C local rev-parse --verify refs/remotes/origin/master >actual &&
test_cmp expected actual
'
test_expect_success 'server is initially behind - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
inconsistency master "master^" &&
git -C local fetch &&
git -C "$REPO" rev-parse --verify "master" >expected &&
git -C local rev-parse --verify refs/remotes/origin/master >actual &&
test_cmp expected actual
'
test_expect_success 'server loses a ref - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
test_must_fail git -C local fetch 2>err &&
test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
'
# DO NOT add non-httpd-specific tests here, because the last part of this
# test script is only executed when httpd is available and enabled.
test_done