Skip to contentSkip to conversation

test-lib: limit the output of the yes utility

PATCH Superseded Johannes Sixt 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test-lib: limit the output of the yes utility

On Windows, there is no SIGPIPE. A consequence of this is that the upstream process of a pipe does not notice the death of the downstream process until the pipe buffer is full and writing more data returns an error. This behavior is the reason for an annoying delay during the execution of t7610-mergetool.sh: There are a number of test cases where 'yes' is invoked upstream. Since the utility is basically an endless loop it runs, on Windows, until the pipe buffer is full. This does take a few seconds.

The test suite has its own implementation of 'yes'. Modify it to produce only a limited amount of output that is sufficient for the test suite. The amount chosen should be sufficiently high for any test case, assuming that future test cases will not exaggerate their demands of input from an upstream 'yes' invocation.

---
This does not fix an error, but only an unnecessary sink of CPU cycles and wasted wall clock time.

 t/test-lib.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
t/test-lib.sh +7 -7
index bd4b02e..97e6491 100644
@@ -902,15 +902,15 @@ fi
 yes () {
 	if test $# = 0
 	then
-		y=y
+		set -- y
 	else
-		y="$*"
+		set -- "$*"
 	fi
-
-	while echo "$y"
-	do
-		:
-	done
+	# we do not need an infinite supply of output for tests
+	set -- "$@" "$@" "$@" "$@"	# 4
+	set -- "$@" "$@" "$@" "$@"	# 16
+	set -- "$@" "$@" "$@" "$@"	# 64
+	printf "%s\n" "$@"
 }
 
 # Fix some commands on Windows
Signature · 1 line
2.7.0.118.g90056ae
#1 lore raw

Hi Hannes,

Quoted 1 line · Johannes Sixt

On Windows, there is no SIGPIPE.

True. But we do get some sort of write failure, no? Otherwise
https://github.com/git/git/commit/2b86292ed would not work...

Quoted 15 lines
t/test-lib.sh +2 -3
index bd4b02e..97e6491 100644
@@ -902,15 +902,15 @@ fi
 yes () {
 	if test $# = 0
 	then
-		y=y
+		set -- y
 	else
-		y="$*"
+		set -- "$*"
 	fi
-

t/test-lib.sh fi · line 914

Quoted 10 lines
t/test-lib.sh +5 -4
-	while echo "$y"
-	do
-		:
-	done
+	# we do not need an infinite supply of output for tests
+	set -- "$@" "$@" "$@" "$@"	# 4
+	set -- "$@" "$@" "$@" "$@"	# 16
+	set -- "$@" "$@" "$@" "$@"	# 64
+	printf "%s\n" "$@"
 }

I agree with the idea, but I would like to have a less intrusive patch. Something like this should do the job as well, and is a little easier on the eyes IMHO:

-- snipsnap --

t/test-lib.sh +4 -2
index 32ac1a6..ae381b9 100644
@@ -907,9 +907,11 @@ yes () {
 		y="$*"
 	fi
 
-	while echo "$y"
+	i=0
+	while test $i -lt 99
 	do
-		:
+		echo "$y"
+		i=$(($i+1))
 	done
 }
 
#2 lore raw

PATCH v2 1/1 test-lib: limit the output of the yes utility

From: Johannes Schindelin <[email protected]>

On Windows, there is no SIGPIPE. A consequence of this is that the upstream process of a pipe does not notice the death of the downstream process until the pipe buffer is full and writing more data returns an error. This behavior is the reason for an annoying delay during the execution of t7610-mergetool.sh: There are a number of test cases where 'yes' is invoked upstream. Since the utility is basically an endless loop it runs, on Windows, until the pipe buffer is full. This does take a few seconds.

The test suite has its own implementation of 'yes'. Modify it to produce only a limited amount of output that is sufficient for the test suite. The amount chosen should be sufficiently high for any test case, assuming that future test cases will not exaggerate their demands of input from an upstream 'yes' invocation.

[j6t: commit message]

---
Am 02.02.2016 um 09:21 schrieb Johannes Schindelin:

Quoted 5 lines · Johannes Sixt
Quoted 1 line

On Windows, there is no SIGPIPE.

True. But we do get some sort of write failure, no? Otherwise
https://github.com/git/git/commit/2b86292ed would not work...

Of course. See the second sentence of the commit message.

Quoted 3 lines

I agree with the idea, but I would like to have a less intrusive patch. Something like this should do the job as well, and is a little easier on the eyes IMHO:

I'm not 100% satisfied with your version because it stomps on short-and-sweet shell variables $i and $y. But then the utility only occurs upstream of a pipeline in a separate process, so that does not matter.

Please allow me to pass authorship to you, since the patch text is now all yours, and to forge your sign-off.

-- Hannes

 t/test-lib.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
t/test-lib.sh +4 -2
index bd4b02e..51e4a88 100644
@@ -907,9 +907,11 @@ yes () {
 		y="$*"
 	fi
 
-	while echo "$y"
+	i=0
+	while test $i -lt 99
 	do
-		:
+		echo "$y"
+		i=$(($i+1))
 	done
 }
 
Signature · 1 line
2.7.0.118.g90056ae
#3 lore raw

Hi Hannes,

Quoted 2 lines · Johannes Sixt

I'm not 100% satisfied with your version because it stomps on short-and-sweet shell variables $i and $y.

Please note that $y was already stomped on before my patch.

Quoted 2 lines

But then the utility only occurs upstream of a pipeline in a separate process, so that does not matter.

That was my thinking, too.

Quoted 2 lines

Please allow me to pass authorship to you, since the patch text is now all yours, and to forge your sign-off.

Fair enough,
Dscho