upload-pack: test negotiation with changing repository
Add tests to check the behavior of fetching from a repository which changes between rounds of negotiation (for example, when different servers in a load-balancing agreement participate in the same stateless RPC negotiation). This forms a baseline of comparison to the ref-in-want functionality (which will be introduced to the client in subsequent commits), and ensures that subsequent commits do not change existing behavior. As part of this effort, a mechanism to substitute strings in a single HTTP response is added. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
516e2b76bd
commit
3374292e55
@ -132,6 +132,7 @@ prepare_httpd() {
|
||||
cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
|
||||
install_script broken-smart-http.sh
|
||||
install_script error.sh
|
||||
install_script apply-one-time-sed.sh
|
||||
|
||||
ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
|
||||
|
||||
|
@ -111,9 +111,14 @@ Alias /auth/dumb/ www/auth/dumb/
|
||||
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
|
||||
SetEnv GIT_HTTP_EXPORT_ALL
|
||||
</LocationMatch>
|
||||
<LocationMatch /one_time_sed/>
|
||||
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
|
||||
SetEnv GIT_HTTP_EXPORT_ALL
|
||||
</LocationMatch>
|
||||
ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
|
||||
ScriptAlias /broken_smart/ broken-smart-http.sh/
|
||||
ScriptAlias /error/ error.sh/
|
||||
ScriptAliasMatch /one_time_sed/(.*) apply-one-time-sed.sh/$1
|
||||
<Directory ${GIT_EXEC_PATH}>
|
||||
Options FollowSymlinks
|
||||
</Directory>
|
||||
@ -123,6 +128,9 @@ ScriptAlias /error/ error.sh/
|
||||
<Files error.sh>
|
||||
Options ExecCGI
|
||||
</Files>
|
||||
<Files apply-one-time-sed.sh>
|
||||
Options ExecCGI
|
||||
</Files>
|
||||
<Files ${GIT_EXEC_PATH}/git-http-backend>
|
||||
Options ExecCGI
|
||||
</Files>
|
||||
|
22
t/lib-httpd/apply-one-time-sed.sh
Normal file
22
t/lib-httpd/apply-one-time-sed.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
# If "one-time-sed" exists in $HTTPD_ROOT_PATH, run sed on the HTTP response,
|
||||
# using the contents of "one-time-sed" as the sed command to be run. If the
|
||||
# response was modified as a result, delete "one-time-sed" so that subsequent
|
||||
# HTTP responses are no longer modified.
|
||||
#
|
||||
# This can be used to simulate the effects of the repository changing in
|
||||
# between HTTP request-response pairs.
|
||||
if [ -e one-time-sed ]; then
|
||||
"$GIT_EXEC_PATH/git-http-backend" >out
|
||||
sed "$(cat one-time-sed)" <out >out_modified
|
||||
|
||||
if diff out out_modified >/dev/null; then
|
||||
cat out
|
||||
else
|
||||
cat out_modified
|
||||
rm one-time-sed
|
||||
fi
|
||||
else
|
||||
"$GIT_EXEC_PATH/git-http-backend"
|
||||
fi
|
@ -157,4 +157,72 @@ 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 &&
|
||||
for i in $(seq 1 33); do test_commit s$i; done &&
|
||||
|
||||
# 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 &&
|
||||
grep "ERR upload-pack: not our ref" err
|
||||
'
|
||||
|
||||
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
|
||||
'
|
||||
|
||||
stop_httpd
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user