summaryrefslogtreecommitdiff
path: root/t/t0081-line-buffer.sh
AgeCommit message (Collapse)AuthorFilesLines
2011-03-29tests: kill backgrounded processes more robustlyLibravatar Jeff King1-6/+6
t0081 creates several background processes that write to a fifo and then go to sleep for a while (so the reader of the fifo does not see EOF). Each background process is made in a curly-braced block in the shell, and after we are done reading from the fifo, we use "kill $!" to kill it off. For a simple, single-command process, this works reliably and kills the child sleep process. But for more complex commands like "make_some_output && sleep", the results are less predictable. When executing under bash, we end up with a subshell that gets killed by the $! but leaves the sleep process still alive. This is bad not only for process hygeine (we are leaving random sleep processes to expire after a while), but also interacts badly with the "prove" command. When prove executes a test, it does not realize the test is done when it sees SIGCHLD, but rather waits until the test's stdout pipe is closed. The orphaned sleep process may keep that pipe open via test-lib's file descriptor 5, causing prove to hang for 100 seconds. The solution is to explicitly use a subshell and to exec the final sleep process, so that when we "kill $!" we get the process id of the sleep process. [jn: original patch by Jeff had some additional bits: 1. Wrap the "kill" in a test_when_finished, since we want to clean up the process whether the test succeeds or not. 2. The "kill" is part of our && chain for test success. It probably won't fail, but it can if the process has expired before we manage to kill it. So let's mark it as OK to fail. I'm postponing that for now.] Reported-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-03-26vcs-svn: remove buffer_read_stringLibravatar Jonathan Nieder1-22/+13
All previous users of buffer_read_string have already been converted to use the more intuitive buffer_read_binary, so remove the old API to avoid some confusion. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-02-26vcs-svn: allow input from file descriptorLibravatar Jonathan Nieder1-0/+9
Based-on-patch-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-02-26vcs-svn: add binary-safe read functionLibravatar Jonathan Nieder1-0/+18
buffer_read_string works well for non line-oriented input except for one problem: it does not tell the caller how many bytes were actually written. This means that unless one is very careful about checking for errors (and eof) the calling program cannot tell the difference between the string "foo" followed by an early end of file and the string "foo\0bar\0baz". So introduce a variant that reports the length, too, a thinner wrapper around strbuf_fread. Its result is written to a strbuf so the caller does not need to keep track of the number of bytes read. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-02-26t0081 (line-buffer): add buffering testsLibravatar Jonathan Nieder1-1/+109
POSIX makes the behavior of read(2) from a pipe fairly clear: a read from an empty pipe will block until there is data available and any other read will not block, prefering to return a partial result. Likewise, fread(3) and fgets(3) are clearly specified to act as though implemented by calling fgetc(3) in a simple loop. But the buffering behavior of fgetc is less clear. Luckily, no sane platform is going to implement fgetc by calling the equivalent of read(2) more than once. fgetc has to be able to return without filling its buffer to preserve errno when errors are encountered anyway. So let's assume the simpler behavior (trust) but add some tests to catch insane platforms that violate that when they come (verify). First check that fread can handle a 0-length read from an empty fifo. Because open(O_RDONLY) blocks until the writing end is open, open the writing end of the fifo in advance in a subshell. Next try short inputs from a pipe that is not filled all the way. Lastly (two tests) try very large inputs from a pipe that will not fit in the relevant buffers. The first of these tests reads a little more than 8192 bytes, which is BUFSIZ (the size of stdio's buffers) on this Linux machine. The second reads a little over 64 KiB (the pipe capacity on Linux) and is not run unless requested by setting the GIT_REMOTE_SVN_TEST_BIG_FILES environment variable. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-02-26vcs-svn: tweak test-line-buffer to not assume line-oriented inputLibravatar Jonathan Nieder1-14/+13
Do not expect an implicit newline after each input record. Use a separate command to exercise buffer_skip_bytes. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-02-26tests: give vcs-svn/line_buffer its own test scriptLibravatar Jonathan Nieder1-0/+67
Split the line_buffer test into small pieces and move it to its own file as preparation for adding more tests. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>