Skip to content

Commit b96114e

Browse files
aspiersgitster
authored andcommitted
t0008: use named pipe (FIFO) to test check-ignore streaming
sleeps in the check-ignore test suite are not ideal since they can fail when the system is under load, or when a tool like valgrind is used which drastically alters the timing. Therefore we replace them with a more robust solution using a named pipe (FIFO). Thanks to Jeff King for coming up with the redirection wizardry required to make this work. http://article.gmane.org/gmane.comp.version-control.git/220916 Signed-off-by: Adam Spiers <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1ed7fe commit b96114e

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

t/t0008-ignores.sh

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -688,27 +688,23 @@ do
688688
'
689689
done
690690

691-
test_expect_success 'setup: have stdbuf?' '
692-
if which stdbuf >/dev/null 2>&1
693-
then
694-
test_set_prereq STDBUF
695-
fi
696-
'
697-
698-
test_expect_success STDBUF 'streaming support for --stdin' '
699-
(
700-
echo one
701-
sleep 2
702-
echo two
703-
) | stdbuf -oL git check-ignore -v -n --stdin >out &
704-
pid=$! &&
705-
sleep 1 &&
706-
grep "^\.gitignore:1:one one" out &&
707-
test $( wc -l <out ) = 1 &&
708-
sleep 2 &&
709-
grep "^:: two" out &&
710-
test $( wc -l <out ) = 2 &&
711-
( wait $pid || kill $pid || : ) 2>/dev/null
691+
test_expect_success PIPE 'streaming support for --stdin' '
692+
mkfifo in out &&
693+
(git check-ignore -n -v --stdin <in >out &) &&
694+
695+
# We cannot just "echo >in" because check-ignore would get EOF
696+
# after echo exited; instead we open the descriptor in our
697+
# shell, and then echo to the fd. We make sure to close it at
698+
# the end, so that the subprocess does get EOF and dies
699+
# properly.
700+
exec 9>in &&
701+
test_when_finished "exec 9>&-" &&
702+
echo >&9 one &&
703+
read response <out &&
704+
echo "$response" | grep "^\.gitignore:1:one one" &&
705+
echo >&9 two &&
706+
read response <out &&
707+
echo "$response" | grep "^:: two"
712708
'
713709

714710
test_done

0 commit comments

Comments
 (0)