[PATCH 02/10] t7422: fix flaky test caused by buffered stdout
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jan 3, 2025, 14:46 UTC
- Message-ID
- <20250103-b4-pks-ci-fixes-v1-2-a9bb95dff833@pks.im>
- In-Reply-To
- <20250103-b4-pks-ci-fixes-v1-0-a9bb95dff833@pks.im>
One test in t7422 asserts that `git submodule status --recursive` properly handles SIGPIPE. This test is flaky though and may sometimes not see a SIGPIPE at all:
expecting success of 7422.18 'git submodule status --recursive propagates SIGPIPE':
{ git submodule status --recursive 2>err; echo $?>status; } |
grep -q X/S &&
test_must_be_empty err &&
test_match_signal 13 "$(cat status)"
++ git submodule status --recursive
++ grep -q X/S
++ echo 0
++ test_must_be_empty err
++ test 1 -ne 1
++ test_path_is_file err
++ test 1 -ne 1
++ test -f err
++ test -s err
+++ cat status
++ test_match_signal 13 0
++ test 0 = 141
++ test 0 = 269
++ return 1
error: last command exited with $?=1
not ok 18 - git submodule status --recursive propagates SIGPIPEThe issue is caused by us using grep(1) to terminate the pipe on the first matching line in the recursing git-submodule(1) process. Standard streams are typically buffered though, so this condition is racy and may cause us to terminate the pipe after git-submodule(1) has already exited, and in that case we wouldn't see the expected signal.
Fix the issue by converting standard streams to be unbuffered. I have only been able to reproduce this issue a single time after running t7422 with `--stress` after an extended amount of time, so I cannot claim to be fully certain that this fix is sufficient.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- t/t7422-submodule-output.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/t/t7422-submodule-output.sh b/t/t7422-submodule-output.sh index f21e9203678b94701281d5339ae8bfe53d5de0ed..ba843c02c9c2da198578aec5716813de32960b86 100755 --- a/t/t7422-submodule-output.sh +++ b/t/t7422-submodule-output.sh @@ -166,9 +166,13 @@ do ' done -test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE' ' - { git submodule status --recursive 2>err; echo $?>status; } | - grep -q X/S && +test_lazy_prereq STDBUF ' + stdbuf --version +' + +test_expect_success !MINGW,STDBUF 'git submodule status --recursive propagates SIGPIPE' ' + { stdbuf -oL git submodule status --recursive 2>err; echo $?>status; } | + stdbuf -i0 grep -q X/S && test_must_be_empty err && test_match_signal 13 "$(cat status)" '
-- 2.48.0.rc1.241.g6c04ab211c.dirty