Skip to content

Commit 314a73d

Browse files
peffgitster
authored andcommitted
t/lib-git-daemon: record daemon log
When we start git-daemon for our tests, we send its stderr log stream to a named pipe. We synchronously read the first line to make sure that the daemon started, and then dump the rest to descriptor 4. This is handy for debugging test output with "--verbose", but the tests themselves can't access the log data. Let's dump the log into a file, as well, so that future tests can check the log. There are a few subtleties worth calling out here: - we'll continue to send output to descriptor 4 for viewing/debugging, which would imply swapping out "cat" for "tee". But we want to ensure that there's no buffering, and "tee" doesn't have a standard way to ask for that. So we'll use a shell loop around "read" and "printf" instead. That ensures that after a request has been served, the matching log entries will have made it to the file. - the existing first-line shell loop used read/echo. We'll switch to consistently using "read -r" and "printf" to relay data as faithfully as possible. - we open the logfile for append, rather than just output. That makes it OK for tests to truncate the logfile without restarting the daemon (the OS will atomically seek to the end of the file when outputting each line). That allows tests to look at the log without worrying about pollution from earlier tests. Helped-by: Lucas Werkmeister <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 02adf84 commit 314a73d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

t/lib-git-daemon.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ start_git_daemon() {
5353
"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
5454
>&3 2>git_daemon_output &
5555
GIT_DAEMON_PID=$!
56+
>daemon.log
5657
{
57-
read line <&7
58-
echo >&4 "$line"
59-
cat <&7 >&4 &
60-
} 7<git_daemon_output &&
58+
read -r line <&7
59+
printf "%s\n" "$line"
60+
printf >&4 "%s\n" "$line"
61+
(
62+
while read -r line <&7
63+
do
64+
printf "%s\n" "$line"
65+
printf >&4 "%s\n" "$line"
66+
done
67+
) &
68+
} 7<git_daemon_output >>"$TRASH_DIRECTORY/daemon.log" &&
6169

6270
# Check expected output
6371
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"

0 commit comments

Comments
 (0)