Skip to content

Commit

Permalink
do not use GIT_TRACE_PACKET=3 in tests
Browse files Browse the repository at this point in the history
Some test scripts use the GIT_TRACE mechanism to dump
debugging information to descriptor 3 (and point it to a
file using the shell). On Windows, however, bash is unable
to set up descriptor 3. We do not write our trace to the
file, and worse, we may interfere with other operations
happening on descriptor 3, causing tests to fail or even
behave inconsistently.

Prior to commit 97a83fa (upload-pack: remove packet debugging
harness), these tests used GIT_DEBUG_SEND_PACK, which only
supported output to a descriptor. The tests in t5503 were
always broken on Windows, and were marked to be skipped via
the NOT_MINGW prerequisite. In t5700, the tests used to pass
prior to 97a83fa, but only because they were not careful
enough; because we only grepped the trace file, an empty
file looked successful to us. But post-97a83fa, the writing
to descriptor 3 causes "git fetch" to hang (presumably
because we are throwing random bytes into the middle of the
protocol).

Now that we are using the GIT_TRACE mechanism, we can
improve both scripts by asking git to write directly to a
file rather than a descriptor. That fixes the hang in t5700,
and should allow t5503 to successfully run on Windows.

In both cases we now also use "test -s" to double-check that
our trace file actually contains output, which should reduce
the possibility of an erroneously passing test.

Signed-off-by: Jeff King <peff@peff.net>
Tested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Mar 21, 2013
1 parent 2a45520 commit 2ad2327
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
38 changes: 18 additions & 20 deletions t/t5503-tagfollow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ test_description='test automatic tag following'

. ./test-lib.sh

if ! test_have_prereq NOT_MINGW; then
say "GIT_TRACE_PACKET not supported - skipping tests"
fi

# End state of the repository:
#
# T - tag1 S - tag2
Expand All @@ -17,7 +13,7 @@ fi
# \ C - origin/cat \
# origin/master master

test_expect_success NOT_MINGW setup '
test_expect_success setup '
test_tick &&
echo ichi >file &&
git add file &&
Expand All @@ -39,33 +35,35 @@ test_expect_success NOT_MINGW setup '
'

U=UPLOAD_LOG
UPATH="$(pwd)/$U"

test_expect_success NOT_MINGW 'setup expect' '
test_expect_success 'setup expect' '
cat - <<EOF >expect
want $A
EOF
'

get_needs () {
test -s "$1" &&
perl -alne '
next unless $F[1] eq "upload-pack<";
last if $F[2] eq "0000";
print $F[2], " ", $F[3];
' "$@"
' "$1"
}

test_expect_success NOT_MINGW 'fetch A (new commit : 1 connection)' '
test_expect_success 'fetch A (new commit : 1 connection)' '
rm -f $U &&
(
cd cloned &&
GIT_TRACE_PACKET=3 git fetch 3>../$U &&
GIT_TRACE_PACKET=$UPATH git fetch &&
test $A = $(git rev-parse --verify origin/master)
) &&
get_needs $U >actual &&
test_cmp expect actual
'

test_expect_success NOT_MINGW "create tag T on A, create C on branch cat" '
test_expect_success "create tag T on A, create C on branch cat" '
git tag -a -m tag1 tag1 $A &&
T=$(git rev-parse --verify tag1) &&
Expand All @@ -77,18 +75,18 @@ test_expect_success NOT_MINGW "create tag T on A, create C on branch cat" '
git checkout master
'

test_expect_success NOT_MINGW 'setup expect' '
test_expect_success 'setup expect' '
cat - <<EOF >expect
want $C
want $T
EOF
'

test_expect_success NOT_MINGW 'fetch C, T (new branch, tag : 1 connection)' '
test_expect_success 'fetch C, T (new branch, tag : 1 connection)' '
rm -f $U &&
(
cd cloned &&
GIT_TRACE_PACKET=3 git fetch 3>../$U &&
GIT_TRACE_PACKET=$UPATH git fetch &&
test $C = $(git rev-parse --verify origin/cat) &&
test $T = $(git rev-parse --verify tag1) &&
test $A = $(git rev-parse --verify tag1^0)
Expand All @@ -97,7 +95,7 @@ test_expect_success NOT_MINGW 'fetch C, T (new branch, tag : 1 connection)' '
test_cmp expect actual
'

test_expect_success NOT_MINGW "create commits O, B, tag S on B" '
test_expect_success "create commits O, B, tag S on B" '
test_tick &&
echo O >file &&
git add file &&
Expand All @@ -113,18 +111,18 @@ test_expect_success NOT_MINGW "create commits O, B, tag S on B" '
S=$(git rev-parse --verify tag2)
'

test_expect_success NOT_MINGW 'setup expect' '
test_expect_success 'setup expect' '
cat - <<EOF >expect
want $B
want $S
EOF
'

test_expect_success NOT_MINGW 'fetch B, S (commit and tag : 1 connection)' '
test_expect_success 'fetch B, S (commit and tag : 1 connection)' '
rm -f $U &&
(
cd cloned &&
GIT_TRACE_PACKET=3 git fetch 3>../$U &&
GIT_TRACE_PACKET=$UPATH git fetch &&
test $B = $(git rev-parse --verify origin/master) &&
test $B = $(git rev-parse --verify tag2^0) &&
test $S = $(git rev-parse --verify tag2)
Expand All @@ -133,22 +131,22 @@ test_expect_success NOT_MINGW 'fetch B, S (commit and tag : 1 connection)' '
test_cmp expect actual
'

test_expect_success NOT_MINGW 'setup expect' '
test_expect_success 'setup expect' '
cat - <<EOF >expect
want $B
want $S
EOF
'

test_expect_success NOT_MINGW 'new clone fetch master and tags' '
test_expect_success 'new clone fetch master and tags' '
git branch -D cat
rm -f $U
(
mkdir clone2 &&
cd clone2 &&
git init &&
git remote add origin .. &&
GIT_TRACE_PACKET=3 git fetch 3>../$U &&
GIT_TRACE_PACKET=$UPATH git fetch &&
test $B = $(git rev-parse --verify origin/master) &&
test $S = $(git rev-parse --verify tag2) &&
test $B = $(git rev-parse --verify tag2^0) &&
Expand Down
14 changes: 9 additions & 5 deletions t/t5700-clone-reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ cd "$base_dir"

rm -f "$U.D"

test_expect_success 'cloning with reference (no -l -s)' \
'GIT_TRACE_PACKET=3 git clone --reference B "file://$(pwd)/A" D 3>"$U.D"'
test_expect_success 'cloning with reference (no -l -s)' '
GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
'

test_expect_success 'fetched no objects' \
'! grep " want" "$U.D"'
test_expect_success 'fetched no objects' '
test -s "$U.D" &&
! grep " want" "$U.D"
'

cd "$base_dir"

Expand Down Expand Up @@ -173,9 +176,10 @@ test_expect_success 'fetch with incomplete alternates' '
(
cd K &&
git remote add J "file://$base_dir/J" &&
GIT_TRACE_PACKET=3 git fetch J 3>"$U.K"
GIT_TRACE_PACKET=$U.K git fetch J
) &&
master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
test -s "$U.K" &&
! grep " want $master_object" "$U.K" &&
tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
! grep " want $tag_object" "$U.K"
Expand Down

0 comments on commit 2ad2327

Please sign in to comment.