t5541: run "used receive-pack service" test earlier

There's a test in t5541 that confirms that "git push" makes two requests (a GET to /info/refs, and a POST to /git-receive-pack). However, it's a noop unless GIT_TEST_PROTOCOL_VERSION is set to "0", due to 8a1b0978ab (test: request GIT_TEST_PROTOCOL_VERSION=0 when appropriate, 2019-12-23). This means that almost nobody runs it. And indeed, it has been broken since b0c4adcdd7 (remote-curl: send Accept-Language header to server, 2022-07-11). But the fault is not in that commit, but in how brittle the test is. It runs after several operations have been performed, which means that it expects to see the complete set of requests made so far in the script. Commit b0c4adcdd7 added a new test, which means that the "used receive-pack service" test must be updated, too. Let's fix this by making the test less brittle. We'll move it higher in the script, right after the first push has completed. And we'll clear the access log right before doing the push, so we'll see only the requests from that command. This is technically testing less, in that we won't check that all of those other requests also correctly used smart http. But there's no particular reason think that if the first one did, the others wouldn't. After this patch, running: GIT_TEST_PROTOCOL_VERSION=0 ./t5541-http-push-smart.sh passes, whereas it did not before. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 23, 2023 at 05:49 UTC 77fb36aa7eba5161c34dbe70ba4dd5449e079c87
1 file changed +18 -26
t/t5541-http-push-smart.sh
+18 -26
@@ -41,10 +41,6 @@ GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
41 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
42 EOF
43 test_expect_success 'no empty path components' '
44 - # Clear the log, so that it does not affect the "used receive-pack
45 - # service" test which reads the log too.
46 - test_when_finished ">\"\$HTTPD_ROOT_PATH\"/access.log" &&
47 -
44 # In the URL, add a trailing slash, and see if git appends yet another
45 # slash.
46 cd "$ROOT_PATH" &&
@@ -67,6 +63,10 @@ test_expect_success 'clone remote repository' '
63 '
64
65 test_expect_success 'push to remote repository (standard)' '
66 + # Clear the log, so that the "used receive-pack service" test below
67 + # sees just what we did here.
68 + >"$HTTPD_ROOT_PATH"/access.log &&
69 +
70 cd "$ROOT_PATH"/test_repo_clone &&
71 : >path2 &&
72 git add path2 &&
@@ -80,6 +80,20 @@ test_expect_success 'push to remote repository (standard)' '
80 test $HEAD = $(git rev-parse --verify HEAD))
81 '
82
83 +test_expect_success 'used receive-pack service' '
84 + cat >exp <<-\EOF &&
85 + GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
86 + POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
87 + EOF
88 +
89 + # NEEDSWORK: If the overspecification of the expected result is reduced, we
90 + # might be able to run this test in all protocol versions.
91 + if test "$GIT_TEST_PROTOCOL_VERSION" = 0
92 + then
93 + check_access_log exp
94 + fi
95 +'
96 +
97 test_expect_success 'push to remote repository (standard) with sending Accept-Language' '
98 cat >exp <<-\EOF &&
99 => Send header: Accept-Language: ko-KR, *;q=0.9
@@ -141,28 +155,6 @@ test_expect_success 'rejected update prints status' '
155 '
156 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
157
144 -cat >exp <<EOF
145 -GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
146 -POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
147 -GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
148 -POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
149 -GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
150 -GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
151 -POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
152 -GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
153 -POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
154 -GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
155 -POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
156 -EOF
157 -test_expect_success 'used receive-pack service' '
158 - # NEEDSWORK: If the overspecification of the expected result is reduced, we
159 - # might be able to run this test in all protocol versions.
160 - if test "$GIT_TEST_PROTOCOL_VERSION" = 0
161 - then
162 - check_access_log exp
163 - fi
164 -'
165 -
158 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
159 "$ROOT_PATH"/test_repo_clone main success
160