Skip to content

Commit bc6d33e

Browse files
committed
Merge branch 'sg/httpd-test-unflake'
httpd tests saw occasional breakage due to the way its access log gets inspected by the tests, which has been updated to make them less flaky. * sg/httpd-test-unflake: t/lib-httpd: avoid occasional failures when checking access.log t/lib-httpd: add the strip_access_log() helper function t5541: clean up truncating access log
2 parents 5e98080 + e8b3b2e commit bc6d33e

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

t/lib-httpd.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,24 @@ expect_askpass() {
288288
test_cmp "$TRASH_DIRECTORY/askpass-expect" \
289289
"$TRASH_DIRECTORY/askpass-query"
290290
}
291+
292+
strip_access_log() {
293+
sed -e "
294+
s/^.* \"//
295+
s/\"//
296+
s/ [1-9][0-9]*\$//
297+
s/^GET /GET /
298+
" "$HTTPD_ROOT_PATH"/access.log
299+
}
300+
301+
# Requires one argument: the name of a file containing the expected stripped
302+
# access log entries.
303+
check_access_log() {
304+
sort "$1" >"$1".sorted &&
305+
strip_access_log >access.log.stripped &&
306+
sort access.log.stripped >access.log.sorted &&
307+
if ! test_cmp "$1".sorted access.log.sorted
308+
then
309+
test_cmp "$1" access.log.stripped
310+
fi
311+
}

t/t5541-http-push-smart.sh

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,16 @@ GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
3838
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
3939
EOF
4040
test_expect_success 'no empty path components' '
41+
# Clear the log, so that it does not affect the "used receive-pack
42+
# service" test which reads the log too.
43+
test_when_finished ">\"\$HTTPD_ROOT_PATH\"/access.log" &&
44+
4145
# In the URL, add a trailing slash, and see if git appends yet another
4246
# slash.
4347
cd "$ROOT_PATH" &&
4448
git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
4549
46-
sed -e "
47-
s/^.* \"//
48-
s/\"//
49-
s/ [1-9][0-9]*\$//
50-
s/^GET /GET /
51-
" >act <"$HTTPD_ROOT_PATH"/access.log &&
52-
53-
# Clear the log, so that it does not affect the "used receive-pack
54-
# service" test which reads the log too.
55-
#
56-
# We do this before the actual comparison to ensure the log is cleared.
57-
echo > "$HTTPD_ROOT_PATH"/access.log &&
58-
59-
test_cmp exp act
50+
check_access_log exp
6051
'
6152

6253
test_expect_success 'clone remote repository' '
@@ -124,7 +115,6 @@ test_expect_success 'rejected update prints status' '
124115
rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
125116

126117
cat >exp <<EOF
127-
128118
GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
129119
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
130120
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
@@ -138,13 +128,7 @@ GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
138128
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
139129
EOF
140130
test_expect_success 'used receive-pack service' '
141-
sed -e "
142-
s/^.* \"//
143-
s/\"//
144-
s/ [1-9][0-9]*\$//
145-
s/^GET /GET /
146-
" >act <"$HTTPD_ROOT_PATH"/access.log &&
147-
test_cmp exp act
131+
check_access_log exp
148132
'
149133

150134
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \

t/t5551-http-fetch-smart.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
103103
POST /smart/repo.git/git-upload-pack HTTP/1.1 200
104104
EOF
105105
test_expect_success 'used upload-pack service' '
106-
sed -e "
107-
s/^.* \"//
108-
s/\"//
109-
s/ [1-9][0-9]*\$//
110-
s/^GET /GET /
111-
" >act <"$HTTPD_ROOT_PATH"/access.log &&
112-
test_cmp exp act
106+
check_access_log exp
113107
'
114108

115109
test_expect_success 'follow redirects (301)' '

t/t5561-http-backend.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,7 @@ GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
129129
POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
130130
EOF
131131
test_expect_success 'server request log matches test results' '
132-
sed -e "
133-
s/^.* \"//
134-
s/\"//
135-
s/ [1-9][0-9]*\$//
136-
s/^GET /GET /
137-
" >act <"$HTTPD_ROOT_PATH"/access.log &&
138-
test_cmp exp act
132+
check_access_log exp
139133
'
140134

141135
stop_httpd

0 commit comments

Comments
 (0)