git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] daemon: add tests

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 4, 2012, 20:13 UTC
Message-ID
<7vehvfp6ok.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vy5tnpcuw.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 15 quoted lines
> Clemens Buchacher <drizzd@aon.at> writes:
> ...
>>> >> +	# kill git-daemon child of git
>>> >> +	say >&3 "Stopping git daemon ..."
>>> >> +	pkill -P "$DAEMON_PID"
>>> 
>>> How portable is this one (I usually do not trust use of pkill anywhere)?
>>
>> I read that it is supposed to be more portable than skill or killall.
>> But I have no way to research this. I have implemented a workaround
>> using only 'ps' and 'kill' in [PATCH 3/6] avoid use of pkill.
>
> Yuck, that patch looks even uglier X-<.
>
> Do you really need to kill the children but not the daemon?
To reduce round-trip cost, here is what I'll queue for now.
-- >8 --
From: Clemens Buchacher <drizzd@aon.at>
Date: Wed, 4 Jan 2012 16:55:35 +0100
Subject: [PATCH] daemon: add tests

The semantics of the git daemon tests are similar to the http transport tests. In fact, they are only a slightly modified copy of t5550, plus the newly added remote error tests.

All git-daemon tests will be skipped unless the environment variable GIT_TEST_GIT_DAEMON is set.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/lib-git-daemon.sh   |   56 ++++++++++++++++++
 t/t5570-git-daemon.sh |  148 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 204 insertions(+), 0 deletions(-)
 create mode 100644 t/lib-git-daemon.sh
 create mode 100755 t/t5570-git-daemon.sh
diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh
new file mode 100644
index 0000000..c0ff9e2
--- /dev/null
+++ b/t/lib-git-daemon.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+if test -z "$GIT_TEST_GIT_DAEMON"
+then
+	skip_all="git-daemon testing disabled (define GIT_TEST_GIT_DAEMON to enable)"
+	test_done
+fi
+
+LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-'8121'}
+
+GIT_DAEMON_PID=
+GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
+GIT_DAEMON_URL=git://127.0.0.1:$LIB_GIT_DAEMON_PORT
+
+start_git_daemon() {
+	if test -n "$GIT_DAEMON_PID"
+	then
+		error "start_git_daemon already called"
+	fi
+
+	mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
+
+	trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
+
+	say >&3 "Starting git daemon ..."
+	git daemon --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
+		--reuseaddr --verbose \
+		--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
+		"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
+		>&3 2>&4 &
+	GIT_DAEMON_PID=$!
+}
+
+stop_git_daemon() {
+	if test -z "$GIT_DAEMON_PID"
+	then
+		return
+	fi
+
+	trap 'die' EXIT
+
+	# kill git-daemon child of git
+	say >&3 "Stopping git daemon ..."
+	pkill -P "$GIT_DAEMON_PID"
+	wait "$GIT_DAEMON_PID"
+	ret=$?
+	#
+	# We signal TERM=15 to the child and expect the parent to
+	# exit with 143 = 128+15.
+	#
+	if test $ret -ne 143
+	then
+		error "git daemon exited with status: $ret"
+	fi
+	GIT_DAEMON_PID=
+}
diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh
new file mode 100755
index 0000000..7cbc999
--- /dev/null
+++ b/t/t5570-git-daemon.sh
@@ -0,0 +1,148 @@
+#!/bin/sh
+
+test_description='test fetching over git protocol'
+. ./test-lib.sh
+
+LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-5570}
+. "$TEST_DIRECTORY"/lib-git-daemon.sh
+start_git_daemon
+
+test_expect_success 'setup repository' '
+	echo content >file &&
+	git add file &&
+	git commit -m one
+'
+
+test_expect_success 'create git-accessible bare repository' '
+	mkdir "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
+	(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
+	 git --bare init &&
+	 : >git-daemon-export-ok
+	) &&
+	git remote add public "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
+	git push public master:master
+'
+
+test_expect_success 'clone git repository' '
+	git clone "$GIT_DAEMON_URL/repo.git" clone &&
+	test_cmp file clone/file
+'
+
+test_expect_success 'fetch changes via git protocol' '
+	echo content >>file &&
+	git commit -a -m two &&
+	git push public &&
+	(cd clone && git pull) &&
+	test_cmp file clone/file
+'
+
+test_expect_failure 'remote detects correct HEAD' '
+	git push public master:other &&
+	(cd clone &&
+	 git remote set-head -d origin &&
+	 git remote set-head -a origin &&
+	 git symbolic-ref refs/remotes/origin/HEAD > output &&
+	 echo refs/remotes/origin/master > expect &&
+	 test_cmp expect output
+	)
+'
+
+test_expect_success 'prepare pack objects' '
+	cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
+	(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
+	 git --bare repack -a -d
+	)
+'
+
+test_expect_success 'fetch notices corrupt pack' '
+	cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
+	(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
+	 p=`ls objects/pack/pack-*.pack` &&
+	 chmod u+w $p &&
+	 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
+	) &&
+	mkdir repo_bad1.git &&
+	(cd repo_bad1.git &&
+	 git --bare init &&
+	 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad1.git" &&
+	 test 0 = `ls objects/pack/pack-*.pack | wc -l`
+	)
+'
+
+test_expect_success 'fetch notices corrupt idx' '
+	cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
+	(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
+	 p=`ls objects/pack/pack-*.idx` &&
+	 chmod u+w $p &&
+	 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
+	) &&
+	mkdir repo_bad2.git &&
+	(cd repo_bad2.git &&
+	 git --bare init &&
+	 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
+	 test 0 = `ls objects/pack | wc -l`
+	)
+'
+
+test_remote_error()
+{
+	do_export=YesPlease
+	while test $# -gt 0
+	do
+		case $1 in
+		-x)
+			shift
+			chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
+			;;
+		-n)
+			shift
+			do_export=
+			;;
+		*)
+			break
+		esac
+	done
+
+	if test $# -ne 3
+	then
+		error "invalid number of arguments"
+	fi
+
+	cmd=$1
+	repo=$2
+	msg=$3
+
+	if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
+	then
+		if test -n "$do_export"
+		then
+			: >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
+		else
+			rm -f "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
+		fi
+	fi
+
+	test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" 2>output &&
+	echo "fatal: remote error: $msg: /$repo" >expect &&
+	test_cmp expect output
+	ret=$?
+	chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
+	(exit $ret)
+}
+
+msg="access denied or repository not exported"
+test_expect_success 'clone non-existent' "test_remote_error    clone nowhere.git '$msg'"
+test_expect_success 'push disabled'      "test_remote_error    push  repo.git    '$msg'"
+test_expect_success 'read access denied' "test_remote_error -x fetch repo.git    '$msg'"
+test_expect_success 'not exported'       "test_remote_error -n fetch repo.git    '$msg'"
+
+stop_git_daemon
+start_git_daemon --informative-errors
+
+test_expect_success 'clone non-existent' "test_remote_error    clone nowhere.git 'no such repository'"
+test_expect_success 'push disabled'      "test_remote_error    push  repo.git    'service not enabled'"
+test_expect_success 'read access denied' "test_remote_error -x fetch repo.git    'no such repository'"
+test_expect_success 'not exported'       "test_remote_error -n fetch repo.git    'repository not exported'"
+
+stop_git_daemon
+test_done
-- 
1.7.8.2.340.gd18f0f
Previous: Junio C HamanoNext: Clemens Buchacher
Message 77 of 117 in “transport: do not allow to push over git:// protocol”
  1. transport: do not allow to push over git:// protocolNguyễn Thái Ngọc Duy, Oct 1, 2011
  2. Ilari LiusvaaraOct 1, 2011
  3. Nguyen Thai Ngoc DuyOct 1, 2011
  4. Jonathan NiederOct 1, 2011
  5. Nguyen Thai Ngoc DuyOct 3, 2011
  6. Jeff KingOct 3, 2011
  7. Johannes SixtOct 3, 2011
  8. Jeff KingOct 3, 2011
  9. Nguyen Thai Ngoc DuyOct 3, 2011
  10. Jeff KingOct 3, 2011
  11. Nguyen Thai Ngoc DuyOct 3, 2011
  12. Jonathan NiederOct 3, 2011
  13. daemon: print "access denied" if a service does not workNguyễn Thái Ngọc Duy, Oct 3, 2011
  14. Jonathan NiederOct 3, 2011
  15. Junio C HamanoOct 3, 2011
  16. daemon: return "access denied" if a service is not allowedNguyễn Thái Ngọc Duy, Oct 3, 2011
  17. Junio C HamanoOct 3, 2011
  18. Jeff KingOct 12, 2011
  19. Jonathan NiederOct 13, 2011
  20. Nguyen Thai Ngoc DuyOct 13, 2011
  21. Jonathan NiederOct 13, 2011
  22. Nguyen Thai Ngoc DuyOct 13, 2011
  23. Nguyen Thai Ngoc DuyOct 13, 2011
  24. Jeff KingOct 13, 2011
  25. Junio C HamanoOct 14, 2011
  26. Jeff KingOct 14, 2011
  27. Jeff KingOct 14, 2011
  28. Jeff KingOct 14, 2011
  29. Junio C HamanoOct 14, 2011
  30. Jeff KingOct 14, 2011
  31. Junio C HamanoOct 14, 2011
  32. Jeff KingOct 14, 2011
  33. Jonathan NiederOct 14, 2011
  34. Jonathan NiederOct 14, 2011
  35. Jonathan NiederOct 14, 2011
  36. Jeff KingOct 14, 2011
  37. [PATCHv3] daemon: give friendlier error messages to clientsJeff King, Oct 14, 2011
  38. Junio C HamanoOct 14, 2011
  39. Sitaram ChamartyOct 14, 2011
  40. Junio C HamanoOct 15, 2011
  41. Sitaram ChamartyOct 15, 2011
  42. Jakub NarebskiOct 15, 2011
  43. Jonathan NiederOct 15, 2011
  44. Junio C HamanoOct 15, 2011
  45. Jonathan NiederOct 15, 2011
  46. Sitaram ChamartyOct 16, 2011
  47. Nguyen Thai Ngoc DuyOct 15, 2011
  48. 1/2 daemon: add testsClemens Buchacher, Oct 16, 2011
  49. 2/2 daemon: report permission denied error to clientsClemens Buchacher, Oct 16, 2011
  50. Jeff KingOct 17, 2011
  51. Clemens BuchacherOct 17, 2011
  52. Jeff KingOct 17, 2011
  53. Junio C HamanoOct 17, 2011
  54. Clemens BuchacherOct 18, 2011
  55. Clemens BuchacherOct 19, 2011
  56. 2/2 daemon: report permission denied error to clientsClemens Buchacher, Oct 17, 2011
  57. Junio C HamanoOct 21, 2011
  58. Jeff KingOct 17, 2011
  59. use test number as port numberClemens Buchacher, Oct 17, 2011
  60. Junio C HamanoOct 17, 2011
  61. Clemens BuchacherOct 18, 2011
  62. Clemens BuchacherOct 17, 2011
  63. Jeff KingOct 17, 2011
  64. Jonathan NiederJan 2, 2012
  65. Clemens BuchacherJan 2, 2012
  66. Jeff KingJan 3, 2012
  67. Junio C HamanoJan 3, 2012
  68. Clemens BuchacherJan 4, 2012
  69. 1/6 t5550: repack everything into one fileClemens Buchacher, Jan 4, 2012
  70. Junio C HamanoJan 4, 2012
  71. 2/6 daemon: add testsClemens Buchacher, Jan 4, 2012
  72. 3/6 avoid use of pkillClemens Buchacher, Jan 4, 2012
  73. 4/6 explain expected exit codeClemens Buchacher, Jan 4, 2012
  74. 5/6 t5570: repack everything into one fileClemens Buchacher, Jan 4, 2012
  75. 6/6 chmod: use lower-case xClemens Buchacher, Jan 4, 2012
  76. Junio C HamanoJan 4, 2012
  77. Junio C HamanoJan 4, 2012
  78. Clemens BuchacherJan 4, 2012
  79. Junio C HamanoJan 4, 2012
  80. Jeff KingJan 4, 2012
  81. Clemens BuchacherJan 5, 2012
  82. Junio C HamanoJan 5, 2012
  83. Clemens BuchacherJan 5, 2012
  84. Jeff KingJan 5, 2012
  85. Clemens BuchacherJan 5, 2012
  86. Jeff KingJan 6, 2012
  87. Clemens BuchacherJan 6, 2012
  88. Jeff KingJan 6, 2012
  89. credentials: unable to connect to cache daemonClemens Buchacher, Jan 7, 2012
  90. Jeff KingJan 7, 2012
  91. Junio C HamanoJan 6, 2012
  92. Clemens BuchacherJan 7, 2012
  93. 1/5 run-command: optionally kill children on exitClemens Buchacher, Jan 7, 2012
  94. Erik Faye-LundJan 7, 2012
  95. Clemens BuchacherJan 8, 2012
  96. Jeff KingJan 7, 2012
  97. 2/5 run-command: kill children on exit by defaultClemens Buchacher, Jan 7, 2012
  98. Jeff KingJan 7, 2012
  99. Junio C HamanoJan 8, 2012
  100. 2/5 dashed externals: kill children on exitClemens Buchacher, Jan 8, 2012
  101. Jeff KingJan 8, 2012
  102. 3/5 git-daemon: add testsClemens Buchacher, Jan 7, 2012
  103. 4/5 git-daemon: produce output when readyClemens Buchacher, Jan 7, 2012
  104. 5/5 git-daemon tests: wait until daemon is readyClemens Buchacher, Jan 7, 2012
  105. Jakub NarebskiJan 5, 2012
  106. Jeff KingJan 5, 2012
  107. Jakub NarebskiJan 6, 2012
  108. Clemens BuchacherJan 7, 2012
  109. Brian GernhardtJan 6, 2012
  110. Jakub NarebskiOct 3, 2011
  111. Jeff KingOct 3, 2011
  112. Ilari LiusvaaraOct 3, 2011
  113. Support ERR in remote archive like in fetch/pushJonathan Nieder, Oct 3, 2011
  114. René ScharfeOct 3, 2011
  115. Nguyen Thai Ngoc DuyOct 3, 2011
  116. Junio C HamanoOct 3, 2011
  117. Nguyen Thai Ngoc DuyOct 2, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.