2018-07-16 18:44:01 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='test skipping fetch negotiator'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2023-03-28 14:04:20 +00:00
|
|
|
test_expect_success 'fetch.negotiationalgorithm config' '
|
|
|
|
test_when_finished "rm -rf repo" &&
|
|
|
|
git init repo &&
|
|
|
|
cat >repo/.git/config <<-\EOF &&
|
|
|
|
[fetch]
|
|
|
|
negotiationAlgorithm
|
|
|
|
EOF
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
error: missing value for '\''fetch.negotiationalgorithm'\''
|
|
|
|
fatal: bad config variable '\''fetch.negotiationalgorithm'\'' in file '\''.git/config'\'' at line 2
|
|
|
|
EOF
|
|
|
|
test_expect_code 128 git -C repo fetch >out 2>actual &&
|
|
|
|
test_must_be_empty out &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2018-07-16 18:44:01 +00:00
|
|
|
have_sent () {
|
|
|
|
while test "$#" -ne 0
|
|
|
|
do
|
|
|
|
grep "fetch> have $(git -C client rev-parse $1)" trace
|
|
|
|
if test $? -ne 0
|
|
|
|
then
|
|
|
|
echo "No have $(git -C client rev-parse $1) ($1)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
have_not_sent () {
|
|
|
|
while test "$#" -ne 0
|
|
|
|
do
|
|
|
|
grep "fetch> have $(git -C client rev-parse $1)" trace
|
|
|
|
if test $? -eq 0
|
|
|
|
then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
t5552: suppress upload-pack trace output
The t5552 test script uses GIT_TRACE_PACKET to monitor what
git-fetch sends and receives. However, because we're
accessing a local repository, the child upload-pack also
sends trace output to the same file.
On Linux, this works out OK. We open the trace file with
O_APPEND, so all writes are atomically positioned at the end
of the file. No data can be overwritten or omitted. And
since we prepare our small writes in a strbuf and write them
with a single write(), we should see each line as an atomic
unit. The order of lines between the two processes is
undefined, but the test script greps only for "fetch>" or
"fetch<" lines. So under Linux, the test results are
deterministic.
The test fails intermittently on Windows, however,
reportedly even overwriting bits of the output file (i.e.,
O_APPEND does not seem to give us an atomic position+write).
Since the test only cares about the trace output from fetch,
we can just disable the output from upload-pack. That
doesn't solve the greater question of O_APPEND/trace issues
under Windows, but it easily fixes the flakiness from this
test.
Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-10 14:09:08 +00:00
|
|
|
# trace_fetch <client_dir> <server_dir> [args]
|
|
|
|
#
|
|
|
|
# Trace the packet output of fetch, but make sure we disable the variable
|
|
|
|
# in the child upload-pack, so we don't combine the results in the same file.
|
|
|
|
trace_fetch () {
|
|
|
|
client=$1; shift
|
|
|
|
server=$1; shift
|
|
|
|
GIT_TRACE_PACKET="$(pwd)/trace" \
|
|
|
|
git -C "$client" fetch \
|
|
|
|
--upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
|
|
|
|
"$server" "$@"
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:44:01 +00:00
|
|
|
test_expect_success 'commits with no parents are sent regardless of skip distance' '
|
|
|
|
git init server &&
|
|
|
|
test_commit -C server to_fetch &&
|
|
|
|
|
|
|
|
git init client &&
|
2018-08-24 15:20:12 +00:00
|
|
|
for i in $(test_seq 7)
|
2018-07-16 18:44:01 +00:00
|
|
|
do
|
2021-12-09 05:11:14 +00:00
|
|
|
test_commit -C client c$i || return 1
|
2018-07-16 18:44:01 +00:00
|
|
|
done &&
|
|
|
|
|
|
|
|
# We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
|
|
|
|
# "c1" has no parent, it is still sent as "have" even though it would
|
|
|
|
# normally be skipped.
|
|
|
|
test_config -C client fetch.negotiationalgorithm skipping &&
|
t5552: suppress upload-pack trace output
The t5552 test script uses GIT_TRACE_PACKET to monitor what
git-fetch sends and receives. However, because we're
accessing a local repository, the child upload-pack also
sends trace output to the same file.
On Linux, this works out OK. We open the trace file with
O_APPEND, so all writes are atomically positioned at the end
of the file. No data can be overwritten or omitted. And
since we prepare our small writes in a strbuf and write them
with a single write(), we should see each line as an atomic
unit. The order of lines between the two processes is
undefined, but the test script greps only for "fetch>" or
"fetch<" lines. So under Linux, the test results are
deterministic.
The test fails intermittently on Windows, however,
reportedly even overwriting bits of the output file (i.e.,
O_APPEND does not seem to give us an atomic position+write).
Since the test only cares about the trace output from fetch,
we can just disable the output from upload-pack. That
doesn't solve the greater question of O_APPEND/trace issues
under Windows, but it easily fixes the flakiness from this
test.
Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-10 14:09:08 +00:00
|
|
|
trace_fetch client "$(pwd)/server" &&
|
2018-07-16 18:44:01 +00:00
|
|
|
have_sent c7 c5 c2 c1 &&
|
|
|
|
have_not_sent c6 c4 c3
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'when two skips collide, favor the larger one' '
|
|
|
|
rm -rf server client trace &&
|
|
|
|
git init server &&
|
|
|
|
test_commit -C server to_fetch &&
|
|
|
|
|
|
|
|
git init client &&
|
2018-08-24 15:20:12 +00:00
|
|
|
for i in $(test_seq 11)
|
2018-07-16 18:44:01 +00:00
|
|
|
do
|
2021-12-09 05:11:14 +00:00
|
|
|
test_commit -C client c$i || return 1
|
2018-07-16 18:44:01 +00:00
|
|
|
done &&
|
|
|
|
git -C client checkout c5 &&
|
|
|
|
test_commit -C client c5side &&
|
|
|
|
|
|
|
|
# Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
|
|
|
|
# (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
|
|
|
|
# the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
|
|
|
|
# (from "c5side" skip 1).
|
|
|
|
test_config -C client fetch.negotiationalgorithm skipping &&
|
t5552: suppress upload-pack trace output
The t5552 test script uses GIT_TRACE_PACKET to monitor what
git-fetch sends and receives. However, because we're
accessing a local repository, the child upload-pack also
sends trace output to the same file.
On Linux, this works out OK. We open the trace file with
O_APPEND, so all writes are atomically positioned at the end
of the file. No data can be overwritten or omitted. And
since we prepare our small writes in a strbuf and write them
with a single write(), we should see each line as an atomic
unit. The order of lines between the two processes is
undefined, but the test script greps only for "fetch>" or
"fetch<" lines. So under Linux, the test results are
deterministic.
The test fails intermittently on Windows, however,
reportedly even overwriting bits of the output file (i.e.,
O_APPEND does not seem to give us an atomic position+write).
Since the test only cares about the trace output from fetch,
we can just disable the output from upload-pack. That
doesn't solve the greater question of O_APPEND/trace issues
under Windows, but it easily fixes the flakiness from this
test.
Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-10 14:09:08 +00:00
|
|
|
trace_fetch client "$(pwd)/server" &&
|
2018-07-16 18:44:01 +00:00
|
|
|
have_sent c5side c11 c9 c6 c1 &&
|
|
|
|
have_not_sent c10 c8 c7 c5 c4 c3 c2
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'use ref advertisement to filter out commits' '
|
|
|
|
rm -rf server client trace &&
|
|
|
|
git init server &&
|
|
|
|
test_commit -C server c1 &&
|
|
|
|
test_commit -C server c2 &&
|
|
|
|
test_commit -C server c3 &&
|
|
|
|
git -C server tag -d c1 c2 c3 &&
|
|
|
|
|
|
|
|
git clone server client &&
|
|
|
|
test_commit -C client c4 &&
|
|
|
|
test_commit -C client c5 &&
|
|
|
|
git -C client checkout c4^^ &&
|
|
|
|
test_commit -C client c2side &&
|
|
|
|
|
|
|
|
git -C server checkout --orphan anotherbranch &&
|
|
|
|
test_commit -C server to_fetch &&
|
|
|
|
|
2020-11-18 23:44:34 +00:00
|
|
|
# The server advertising "c3" (as "refs/heads/main") means that we do
|
2018-07-16 18:44:01 +00:00
|
|
|
# not need to send any ancestors of "c3", but we still need to send "c3"
|
|
|
|
# itself.
|
|
|
|
test_config -C client fetch.negotiationalgorithm skipping &&
|
2019-02-25 21:54:13 +00:00
|
|
|
|
|
|
|
# The ref advertisement itself is filtered when protocol v2 is used, so
|
|
|
|
# use v0.
|
2019-12-26 19:55:10 +00:00
|
|
|
(
|
2019-12-24 01:01:10 +00:00
|
|
|
GIT_TEST_PROTOCOL_VERSION=0 &&
|
2019-12-26 19:55:10 +00:00
|
|
|
export GIT_TEST_PROTOCOL_VERSION &&
|
|
|
|
trace_fetch client origin to_fetch
|
|
|
|
) &&
|
2018-07-16 18:44:01 +00:00
|
|
|
have_sent c5 c4^ c2side &&
|
|
|
|
have_not_sent c4 c4^^ c4^^^
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'handle clock skew' '
|
|
|
|
rm -rf server client trace &&
|
|
|
|
git init server &&
|
|
|
|
test_commit -C server to_fetch &&
|
|
|
|
|
|
|
|
git init client &&
|
|
|
|
|
|
|
|
# 2 regular commits
|
|
|
|
test_tick=2000000000 &&
|
|
|
|
test_commit -C client c1 &&
|
|
|
|
test_commit -C client c2 &&
|
|
|
|
|
|
|
|
# 4 old commits
|
|
|
|
test_tick=1000000000 &&
|
|
|
|
git -C client checkout c1 &&
|
|
|
|
test_commit -C client old1 &&
|
|
|
|
test_commit -C client old2 &&
|
|
|
|
test_commit -C client old3 &&
|
|
|
|
test_commit -C client old4 &&
|
|
|
|
|
|
|
|
# "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
|
|
|
|
# normally be skipped, but is treated as a commit without a parent here
|
|
|
|
# and sent, because (due to clock skew) its only parent has already been
|
|
|
|
# popped off the priority queue.
|
|
|
|
test_config -C client fetch.negotiationalgorithm skipping &&
|
t5552: suppress upload-pack trace output
The t5552 test script uses GIT_TRACE_PACKET to monitor what
git-fetch sends and receives. However, because we're
accessing a local repository, the child upload-pack also
sends trace output to the same file.
On Linux, this works out OK. We open the trace file with
O_APPEND, so all writes are atomically positioned at the end
of the file. No data can be overwritten or omitted. And
since we prepare our small writes in a strbuf and write them
with a single write(), we should see each line as an atomic
unit. The order of lines between the two processes is
undefined, but the test script greps only for "fetch>" or
"fetch<" lines. So under Linux, the test results are
deterministic.
The test fails intermittently on Windows, however,
reportedly even overwriting bits of the output file (i.e.,
O_APPEND does not seem to give us an atomic position+write).
Since the test only cares about the trace output from fetch,
we can just disable the output from upload-pack. That
doesn't solve the greater question of O_APPEND/trace issues
under Windows, but it easily fixes the flakiness from this
test.
Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-10 14:09:08 +00:00
|
|
|
trace_fetch client "$(pwd)/server" &&
|
2018-07-16 18:44:01 +00:00
|
|
|
have_sent c2 c1 old4 old2 old1 &&
|
|
|
|
have_not_sent old3
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
|
|
|
|
rm -rf server client trace &&
|
|
|
|
git init server &&
|
|
|
|
test_commit -C server to_fetch &&
|
|
|
|
|
|
|
|
git init client &&
|
2018-08-24 15:20:12 +00:00
|
|
|
for i in $(test_seq 8)
|
2018-07-16 18:44:01 +00:00
|
|
|
do
|
|
|
|
git -C client checkout --orphan b$i &&
|
2021-12-09 05:11:14 +00:00
|
|
|
test_commit -C client b$i.c0 || return 1
|
2018-07-16 18:44:01 +00:00
|
|
|
done &&
|
2018-08-24 15:20:12 +00:00
|
|
|
for j in $(test_seq 19)
|
2018-07-16 18:44:01 +00:00
|
|
|
do
|
2018-08-24 15:20:12 +00:00
|
|
|
for i in $(test_seq 8)
|
2018-07-16 18:44:01 +00:00
|
|
|
do
|
|
|
|
git -C client checkout b$i &&
|
2021-12-09 05:11:14 +00:00
|
|
|
test_commit -C client b$i.c$j || return 1
|
2018-07-16 18:44:01 +00:00
|
|
|
done
|
|
|
|
done &&
|
|
|
|
|
|
|
|
# Copy this branch over to the server and add a commit on it so that it
|
|
|
|
# is reachable but not advertised.
|
|
|
|
git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
|
|
|
|
git -C server checkout b1 &&
|
|
|
|
test_commit -C server commit-on-b1 &&
|
|
|
|
|
|
|
|
test_config -C client fetch.negotiationalgorithm skipping &&
|
fetch test: mark test of "skipping" haves as v0-only
Since 633a53179e (fetch test: avoid use of "VAR= cmd" with a shell
function, 2019-12-26), t5552.5 (do not send "have" with ancestors of
commits that server ACKed) fails when run with
GIT_TEST_PROTOCOL_VERSION=2.
The cause:
The progression of "have"s sent in negotiation depends on whether we
are using a stateless RPC based transport or a stateful bidirectional
one (see for example 44d8dc54e7, "Fix potential local deadlock during
fetch-pack", 2011-03-29). In protocol v2, all transports are
stateless transports, while in protocol v0, transports such as local
access and ssh are stateful.
In stateful transports, the number of "have"s to send multiplies by
two each round until we reach PIPESAFE_FLUSH (that is, 32), and then
it increases by PIPESAFE_FLUSH each round. In stateless transport,
the count multiplies by two each round until we reach LARGE_FLUSH
(which is 16384) and then multiplies by 1.1 each round after that.
Moreover, in stateful transports, as fetch-pack.c explains:
We keep one window "ahead" of the other side, and will wait
for an ACK only on the next one.
This affects t5552.5 because it looks for "have"s from the negotiator
that appear in that second window. With protocol version 2, the
second window never arrives, and the test fails.
Until 633a53179e (2019-12-26), a previous test in the same file
contained
GIT_TEST_PROTOCOL_VERSION= trace_fetch client origin to_fetch
In many common shells (e.g. bash when run as "sh"), the setting of
GIT_TEST_PROTOCOL_VERSION to the empty string lasts beyond the
intended duration of the trace_fetch invocation. This causes it to
override the GIT_TEST_PROTOCOL_VERSION setting that was passed in to
the test during the remainder of the test script, so t5552.5 never got
run using protocol v2 on those shells, regardless of the
GIT_TEST_PROTOCOL_VERSION setting from the environment. 633a53179e
fixed that, revealing the failing test.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-12-26 23:12:51 +00:00
|
|
|
|
|
|
|
# NEEDSWORK: The number of "have"s sent depends on whether the transport
|
|
|
|
# is stateful. If the overspecification of the result were reduced, this
|
|
|
|
# test could be used for both stateful and stateless transports.
|
|
|
|
(
|
|
|
|
# Force protocol v0, in which local transport is stateful (in
|
|
|
|
# protocol v2 it is stateless).
|
|
|
|
GIT_TEST_PROTOCOL_VERSION=0 &&
|
|
|
|
export GIT_TEST_PROTOCOL_VERSION &&
|
|
|
|
trace_fetch client "$(pwd)/server" to_fetch
|
|
|
|
) &&
|
2018-07-16 18:44:01 +00:00
|
|
|
grep " fetch" trace &&
|
|
|
|
|
|
|
|
# fetch-pack sends 2 requests each containing 16 "have" lines before
|
|
|
|
# processing the first response. In these 2 requests, 4 commits from
|
|
|
|
# each branch are sent. Just check the first branch.
|
|
|
|
have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
|
|
|
|
have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
|
|
|
|
|
|
|
|
# While fetch-pack is processing the first response, it should read that
|
|
|
|
# the server ACKs b1.c19 and b1.c17.
|
|
|
|
grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
|
|
|
|
grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
|
|
|
|
|
|
|
|
# fetch-pack should thus not send any more commits in the b1 branch, but
|
|
|
|
# should still send the others (in this test, just check b2).
|
2018-08-24 15:20:12 +00:00
|
|
|
for i in $(test_seq 0 8)
|
2018-07-16 18:44:01 +00:00
|
|
|
do
|
2021-12-09 05:11:14 +00:00
|
|
|
have_not_sent b1.c$i || return 1
|
2018-07-16 18:44:01 +00:00
|
|
|
done &&
|
|
|
|
have_sent b2.c1 b2.c0
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|