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 <git@adamspiers.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Adam Spiers committed
Apr 29, 2013 at 23:55 UTC
b96114edb36e16d214af1e7945a1d19b8a5e1686
1 file changed
+17
-21
t/t0008-ignores.sh
+17
-21
@@ -688,27 +688,23 @@ do
688
'
689
done
690
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"
708
'
709
710
test_done