t1901 - sparse checkout file when lock is taken fails (subtest 19)
Hi All,
This one has me confused. It fails 100% of the time on NonStop. The test looks reasonable, as do the messages. I am not certain that test_i18ngrep works properly - it falls down to the return 1 statement which causes the test to fail. The error message generated is "File already exists" not "File exists" as is required in the test. We should not be testing for specific text content originating from strerror - I thought we had this decision in a different thread.
https://public-inbox.org/git/[email protected]/
Thoughts?
expecting success of 1091.19 'fail when lock is taken':
test_when_finished rm -rf repo/.git/info/sparse-checkout.lock &&
touch repo/.git/info/sparse-checkout.lock &&
test_must_fail git -C repo sparse-checkout set deep 2>err &&
test_i18ngrep "File exists" errerror: 'grep File exists err' didn't find a match in:
fatal: Unable to create '/home/ituglib/randall/git/t/trash directory.t1091-sparse-checkout-builtin/repo/.git/info/sparse-checkout.lock'
: File already exists. <----- this is the test issue
Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier:
remove the file manually to continue.
not ok 19 - fail when lock is taken
#
# test_when_finished rm -rf
repo/.git/info/sparse-checkout.lock &&
# touch repo/.git/info/sparse-checkout.lock && # test_must_fail git -C repo sparse-checkout set deep 2>err && # test_i18ngrep "File exists" err
#
Regards,
Randall
-- Brief whoami:
NonStop developer since approximately 211288444200000000 UNIX developer since approximately 421664400
-- In my real life, I talk too much.
PATCH 1/1 t1091: don't grep for `strerror()` string
We grep for "File exists" in stderr of the failing git sparse-checkout to make sure that it failed for the right reason. We expect the string to show up there since we call strerror(errno) in unable_to_lock_message() in lockfile.c.
On the NonStop platform, this fails because the error string is "File already exists", which doesn't match our grepping.
See 9042140097 ("test-dir-iterator: do not assume errno values", 2019-07-30) for a somewhat similar fix. There, we patched a test helper, which meant we had access to errno and could investigate it better in the test helper instead of just outputting the numerical value and evaluating it in the test script. The current situation is different, since (short of modifying the lockfile machinery, e.g., to be more verbose) we don't have more than the output from strerror() available.
Except we do: We prefix strerror(errno) with _("Unable to create '%s.lock': "). Let's grep for that part instead. It verifies that we were indeed unable to create the lock file. (If that fails for some other reason than the file existing, we really really should expect other tests to fail as well.)
An alternative fix would be to loosen the expression a bit and grep for "File.* exists" instead. There would be no guarantee that some other implementation couldn't come up with another error string, That is, that could be the first move in an endless game of whack-a-mole. Of course, it could also take us from "99" to "100" percent of the platforms and we'd never have this problem again. But since we have another way of addressing this, let's not even try the "loosen it up a bit" strategy.
---
Hi Randall,
Thanks for the report.
Quoted 10 lines
test to fail. The error message generated is "File already exists" not "File exists" as is required in the test. We should not be testing for specific text content originating from strerror - I thought we had this decision in a different thread.
https://public-inbox.org/git/[email protected]/error: 'grep File exists err' didn't find a match in:
fatal: Unable to create '/home/ituglib/randall/git/t/trashdirectory.t1091-sparse-checkout-builtin/repo/.git/info/sparse-checkout.lock'
: File already exists. <----- this is the test issue
Does this patch solve it?
t/t1091-sparse-checkout-builtin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t1091-sparse-checkout-builtin.sh +1 -1
@@ -305,7 +305,7 @@ test_expect_success 'fail when lock is taken' ' test_when_finished rm -rf repo/.git/info/sparse-checkout.lock && touch repo/.git/info/sparse-checkout.lock && test_must_fail git -C repo sparse-checkout set deep 2>err && - test_i18ngrep "File exists" err + test_i18ngrep "Unable to create .*\.lock" err ' test_expect_success '.gitignore should not warn about cone mode' '
Signature · 1 line
2.25.1
Re: [PATCH] t1091: don't grep for `strerror()` string
Quoted 8 lines · Martin Ågren
We grep for "File exists" in stderr of the failing
git sparse-checkoutto make sure that it failed for the right reason. We expect the string to show up there since we callstrerror(errno)inunable_to_lock_message()inlockfile.c.On the NonStop platform, this fails because the error string is "File already exists", which doesn't match our grepping.
Quoted 7 lines
See 9042140097 ("test-dir-iterator: do not assume errno values", 2019-07-30) for a somewhat similar fix. There, we patched a test helper, which meant we had access to
errnoand could investigate it better in the test helper instead of just outputting the numerical value and evaluating it in the test script. The current situation is different, since (short of modifying the lockfile machinery, e.g., to be more verbose) we don't have more than the output fromstrerror()available.
This is the better design, and I should have used it in the first place. The test is really trying to reveal that we are using a .lock file, and the new error message check makes this even more clear.
Quoted 6 lines
Except we do: We prefix
strerror(errno)with_("Unable to create '%s.lock': "). Let's grep for that part instead. It verifies that we were indeed unable to create the lock file. (If that fails for some other reason than the file existing, we really really should expect other tests to fail as well.)
Quoted 7 lines
An alternative fix would be to loosen the expression a bit and grep for "File.* exists" instead. There would be no guarantee that some other implementation couldn't come up with another error string, That is, that could be the first move in an endless game of whack-a-mole. Of course, it could also take us from "99" to "100" percent of the platforms and we'd never have this problem again. But since we have another way of addressing this, let's not even try the "loosen it up a bit" strategy.
Your alternate substring is better than loosening the pattern in several ways.
Quoted 6 lines
Reported-by Randall S. Becker <[email protected]>Signed-off-by Martin Ågren <[email protected]>---
Hi Randall,Thanks for the report.
I'll second the thanks on the report, and extra thanks to Martin for the fix!
Quoted 21 lines
Quoted 10 lines
test to fail. The error message generated is "File already exists" not "File exists" as is required in the test. We should not be testing for specific text content originating from strerror - I thought we had this decision in a different thread.
https://public-inbox.org/git/[email protected]/error: 'grep File exists err' didn't find a match in:
fatal: Unable to create '/home/ituglib/randall/git/t/trashdirectory.t1091-sparse-checkout-builtin/repo/.git/info/sparse-checkout.lock'
: File already exists. <----- this is the test issueDoes this patch solve it?
t/t1091-sparse-checkout-builtin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/t1091-sparse-checkout-builtin.sh +0
-0
t/t1091-sparse-checkout-builtin.sh test_expect_success 'fail when lock is taken' ' · line 311
Quoted 8 lines
t/t1091-sparse-checkout-builtin.sh +1
-1@@ -305,7 +305,7 @@ test_expect_success 'fail when lock is taken' ' test_when_finished rm -rf repo/.git/info/sparse-checkout.lock && touch repo/.git/info/sparse-checkout.lock && test_must_fail git -C repo sparse-checkout set deep 2>err && - test_i18ngrep "File exists" err + test_i18ngrep "Unable to create .*\.lock" err ' test_expect_success '.gitignore should not warn about cone mode' '
This change looks good to me. The commit message is superb.
Thanks,
-Stolee
Re: [PATCH] t1091: don't grep for `strerror()` string
In reply to Martin ÅgrenQuoted 7 lines · Martin Ågren
We grep for "File exists" in stderr of the failing
git sparse-checkoutto make sure that it failed for the right reason. We expect the string to show up there since we callstrerror(errno)inunable_to_lock_message()inlockfile.c.On the NonStop platform, this fails because the error string is "File already exists", which doesn't match our grepping.
Thanks for a quick fix. I agree that looking for our own string makes a lot more sense here.