git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] t3600: fix broken "choking git rm" test
@ 2013-10-16  0:01 SZEDER Gábor
  2013-10-16  0:18 ` Jonathan Nieder
  0 siblings, 1 reply; 4+ messages in thread
From: SZEDER Gábor @ 2013-10-16  0:01 UTC (permalink / raw)
  To: git; +Cc: SZEDER Gábor

The test 'choking "git rm" should not let it die with cruft' is
supposed to check 'git rm's behavior when interrupted by provoking a
SIGPIPE while 'git rm' is busily deleting files from a specially
crafted index.

This test is silently broken for the following reasons:

- The test crafts a special index by feeding a large number of index
  entries with null shas to 'git update-index --index-info'.  It was
  OK back then when this test was introduced in commit 0693f9ddad
  (Make sure lockfiles are unlocked when dying on SIGPIPE,
  2008-12-18), but since commit 4337b5856f (do not write null sha1s to
  on-disk index, 2012-07-28) null shas are not allowed in the on-disk
  index causing 'git update-index' to error out.

- The barfing 'git update-index --index-info' should fail the test,
  but it remains unnoticed because of the severely broken && chain:
  the test's result depends solely on whether there is a stale lock
  file left behind, but after 'git update-index' errors out 'git rm'
  won't be executed at all.

To fix this test feed only non-null shas to 'git update-index' and
restore the && chain (partly by adding a missing && and by using the
test_when_finished helper instead of manual cleanup).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
A particularly funny one from the fallout of gmane/236183

 t/t3600-rm.sh | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 85854f338f..4dd0130dd9 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -240,18 +240,15 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
 
 test_expect_success 'choking "git rm" should not let it die with cruft' '
 	git reset -q --hard &&
+	test_when_finished "rm -f .git/index.lock ; git reset -q --hard" &&
 	i=0 &&
 	while test $i -lt 12000
 	do
-	    echo "100644 $_z40 0	some-file-$i"
+	    echo "100644 1234567890123456789012345678901234567890 0	some-file-$i"
 	    i=$(( $i + 1 ))
 	done | git update-index --index-info &&
-	git rm -n "some-file-*" | :;
-	test -f .git/index.lock
-	status=$?
-	rm -f .git/index.lock
-	git reset -q --hard
-	test "$status" != 0
+	git rm -n "some-file-*" | : &&
+	test ! -f .git/index.lock
 '
 
 test_expect_success 'rm removes subdirectories recursively' '
-- 
1.8.4.1.495.gd8d272e

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t3600: fix broken "choking git rm" test
  2013-10-16  0:01 [PATCH] t3600: fix broken "choking git rm" test SZEDER Gábor
@ 2013-10-16  0:18 ` Jonathan Nieder
  2013-10-16  0:38   ` SZEDER Gábor
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Nieder @ 2013-10-16  0:18 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git

SZEDER Gábor wrote:

> The test 'choking "git rm" should not let it die with cruft' is
> supposed to check 'git rm's behavior when interrupted by provoking a
> SIGPIPE while 'git rm' is busily deleting files from a specially
> crafted index.
>
> This test is silently broken for the following reasons:
[...]
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
> A particularly funny one from the fallout of gmane/236183

Fun. :)  Makes sense.

> --- a/t/t3600-rm.sh
> +++ b/t/t3600-rm.sh
> @@ -240,18 +240,15 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
>  
>  test_expect_success 'choking "git rm" should not let it die with cruft' '
>  	git reset -q --hard &&
> +	test_when_finished "rm -f .git/index.lock ; git reset -q --hard" &&

I'd use "&&" here --- the test_cleanup checks the exit status from
this scriptlet, so it's a good habit.

[...]
> -	test -f .git/index.lock
> -	status=$?
> -	rm -f .git/index.lock
> -	git reset -q --hard
> -	test "$status" != 0
> +	test ! -f .git/index.lock

Gah.  Thanks for cleaning it up.

Maybe test_path_is_missing would make sense here?  (It would notice a
.git/index.lock directory, which is not very likely :), but more
importantly, it says why it is failing the test when it fails.)

With or without the changes mentioned above,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Thanks.

diff --git i/t/t3600-rm.sh w/t/t3600-rm.sh
index 8386b54..540c49b 100755
--- i/t/t3600-rm.sh
+++ w/t/t3600-rm.sh
@@ -240,7 +240,7 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
 
 test_expect_success 'choking "git rm" should not let it die with cruft' '
 	git reset -q --hard &&
-	test_when_finished "rm -f .git/index.lock ; git reset -q --hard" &&
+	test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
 	i=0 &&
 	while test $i -lt 12000
 	do
@@ -248,7 +248,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 	    i=$(( $i + 1 ))
 	done | git update-index --index-info &&
 	git rm -n "some-file-*" | : &&
-	test ! -f .git/index.lock
+	test_path_is_missing .git/index.lock
 '
 
 test_expect_success 'rm removes subdirectories recursively' '

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t3600: fix broken "choking git rm" test
  2013-10-16  0:18 ` Jonathan Nieder
@ 2013-10-16  0:38   ` SZEDER Gábor
  0 siblings, 0 replies; 4+ messages in thread
From: SZEDER Gábor @ 2013-10-16  0:38 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git

On Tue, Oct 15, 2013 at 05:18:04PM -0700, Jonathan Nieder wrote:
> SZEDER Gábor wrote:
> > --- a/t/t3600-rm.sh
> > +++ b/t/t3600-rm.sh
> > @@ -240,18 +240,15 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
> >  
> >  test_expect_success 'choking "git rm" should not let it die with cruft' '
> >  	git reset -q --hard &&
> > +	test_when_finished "rm -f .git/index.lock ; git reset -q --hard" &&
> 
> I'd use "&&" here --- the test_cleanup checks the exit status from
> this scriptlet, so it's a good habit.

OK.  My motivation for the ';' was that we should make sure that both
steps of the cleanup are executed.  However, now thinking about it if
regular 'rm -f' can't remove the lock file then all bets are off
anyway.

> [...]
> > -	test -f .git/index.lock
> > -	status=$?
> > -	rm -f .git/index.lock
> > -	git reset -q --hard
> > -	test "$status" != 0
> > +	test ! -f .git/index.lock
> 
> Gah.  Thanks for cleaning it up.
> 
> Maybe test_path_is_missing would make sense here?  (It would notice a
> .git/index.lock directory, which is not very likely :), but more
> importantly, it says why it is failing the test when it fails.)

I was not aware of the test_path_is_missing helper.  I don't think it
matters whether it's a file or a directory, because a stale
.git/index.lock directory would be just as bad.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] t3600: fix broken "choking git rm" test
@ 2013-10-16  0:48 SZEDER Gábor
  0 siblings, 0 replies; 4+ messages in thread
From: SZEDER Gábor @ 2013-10-16  0:48 UTC (permalink / raw)
  To: Junio C Hamano, Jonathan Nieder; +Cc: git, SZEDER Gábor

The test 'choking "git rm" should not let it die with cruft' is
supposed to check 'git rm's behavior when interrupted by provoking a
SIGPIPE while 'git rm' is busily deleting files from a specially
crafted index.

This test is silently broken for the following reasons:

- The test crafts a special index by feeding a large number of index
  entries with null shas to 'git update-index --index-info'.  It was
  OK back then when this test was introduced in commit 0693f9ddad
  (Make sure lockfiles are unlocked when dying on SIGPIPE,
  2008-12-18), but since commit 4337b5856f (do not write null sha1s to
  on-disk index, 2012-07-28) null shas are not allowed in the on-disk
  index causing 'git update-index' to error out.

- The barfing 'git update-index --index-info' should fail the test,
  but it remains unnoticed because of the severely broken && chain:
  the test's result depends solely on whether there is a stale lock
  file left behind, but after 'git update-index' errors out 'git rm'
  won't be executed at all.

To fix this test feed only non-null shas to 'git update-index' and
restore the && chain (partly by adding a missing && and by using the
test_when_finished helper instead of manual cleanup).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t3600-rm.sh | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 824342f413..ad30a61f9e 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -230,18 +230,15 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
 
 test_expect_success 'choking "git rm" should not let it die with cruft' '
 	git reset -q --hard &&
+	test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
 	i=0 &&
 	while test $i -lt 12000
 	do
-	    echo "100644 $_z40 0	some-file-$i"
+	    echo "100644 1234567890123456789012345678901234567890 0	some-file-$i"
 	    i=$(( $i + 1 ))
 	done | git update-index --index-info &&
-	git rm -n "some-file-*" | :;
-	test -f .git/index.lock
-	status=$?
-	rm -f .git/index.lock
-	git reset -q --hard
-	test "$status" != 0
+	git rm -n "some-file-*" | : &&
+	test_path_is_missing .git/index.lock
 '
 
 test_expect_success 'rm removes subdirectories recursively' '
-- 
1.8.4.1.495.gd8d272e

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-16  0:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-16  0:01 [PATCH] t3600: fix broken "choking git rm" test SZEDER Gábor
2013-10-16  0:18 ` Jonathan Nieder
2013-10-16  0:38   ` SZEDER Gábor
  -- strict thread matches above, loose matches on Subject: below --
2013-10-16  0:48 SZEDER Gábor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).