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

[PATCH 8/7] tests: Fix race condition in t7006-pager

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 22, 2010, 08:46 UTC
Message-ID
<20100222084633.GA14432@progeny.tock>
In-Reply-To
<4B823E21.1060707@viscovery.net>
Pagers that do not consume their input are dangerous: for example,
 $ GIT_PAGER=: git log
 $ echo $?
 141
 $

The only reason these tests were able to work before was that 'git log' would write to the pipe (and not fill it) before the pager had time to terminate and close the pipe.

Fix it by using a program that consumes its input, namely wc (as suggested by Johannes).

Reported-by: Johannes Sixt <j.sixt@viscovery.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Johannes Sixt wrote:
> Don't the following pager settings suffer from a race condition?
Yes.  Thanks for noticing.
 t/t7006-pager.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index da0f962..ec6fd06 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -137,7 +137,7 @@ rm -f default_pager_used
 test_expect_success SIMPLEPAGER 'default pager is used by default' '
 	cat > $less <<-EOF &&
 	#!$SHELL_PATH
-	: > default_pager_used
+	wc > default_pager_used
 	EOF
 	chmod +x $less &&
 	PATH=.:$PATH test_terminal git log &&
@@ -148,7 +148,7 @@ unset GIT_PAGER
 git config --unset core.pager
 rm -f PAGER_used
 test_expect_success TTY 'PAGER overrides default pager' '
-	PAGER=": > PAGER_used" &&
+	PAGER="wc > PAGER_used" &&
 	export PAGER &&
 	test_terminal git log &&
 	test -e PAGER_used
@@ -159,7 +159,7 @@ rm -f core.pager_used
 test_expect_success TTY 'core.pager overrides PAGER' '
 	PAGER=: &&
 	export PAGER &&
-	git config core.pager ": > core.pager_used" &&
+	git config core.pager "wc > core.pager_used" &&
 	test_terminal git log &&
 	test -e core.pager_used
 '
@@ -167,7 +167,7 @@ test_expect_success TTY 'core.pager overrides PAGER' '
 rm -f GIT_PAGER_used
 test_expect_success TTY 'GIT_PAGER overrides core.pager' '
 	git config core.pager : &&
-	GIT_PAGER=": > GIT_PAGER_used" &&
+	GIT_PAGER="wc > GIT_PAGER_used" &&
 	export GIT_PAGER &&
 	test_terminal git log &&
 	test -e GIT_PAGER_used
-- 
1.7.0
Previous: Johannes SixtNext: Jonathan Nieder
Message 13 of 26 in “Re: 'git svn log' no longer uses the pager”
  1. 0/7 Re: 'git svn log' no longer uses the pagerJonathan Nieder, Feb 19, 2010
  2. 1/7 Fix 'git var' usage synopsisJonathan Nieder, Feb 19, 2010
  3. 2/7 Make 'git var GIT_PAGER' always print the configured pagerJonathan Nieder, Feb 19, 2010
  4. 3/7 git.1: Clarify the behavior of the --paginate optionJonathan Nieder, Feb 19, 2010
  5. 4/7 git svn: Fix launching of pagerJonathan Nieder, Feb 19, 2010
  6. 5/7 am: Fix launching of pagerJonathan Nieder, Feb 19, 2010
  7. 6/7 tests: Add tests for automatic use of pagerJonathan Nieder, Feb 19, 2010
  8. Junio C HamanoFeb 20, 2010
  9. 6/7 tests: Add tests for automatic use of pagerJonathan Nieder, Feb 21, 2010
  10. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 21, 2010
  11. Jeff KingFeb 21, 2010
  12. Johannes SixtFeb 22, 2010
  13. 8/7 tests: Fix race condition in t7006-pagerJonathan Nieder, Feb 22, 2010
  14. Jonathan NiederFeb 22, 2010
  15. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 19, 2010
  16. Jeff KingFeb 19, 2010
  17. Jonathan NiederFeb 19, 2010
  18. Jeff KingFeb 19, 2010
  19. Brandon CaseyFeb 19, 2010
  20. Brandon CaseyFeb 20, 2010
  21. Jonathan NiederFeb 20, 2010
  22. Brandon CaseyFeb 20, 2010
  23. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 20, 2010
  24. Junio C HamanoFeb 20, 2010
  25. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 20, 2010
  26. Simplify test-terminal.perlJonathan Nieder, Feb 20, 2010

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.