t7900: fix flaky test due to leaking background job
One of the recently-added tests in t7900 exercises git-maintanance(1) with the `--detach` flag, which causes it to perform maintenance in the background. We do not wait for the backgrounded process to exit though, which causes the process to leak outside of the test, leading to racy behaviour. Fix this by synchronizing with the process via a separate file descriptor. This is the same workaround as we use in t6500, see the function `run_and_wait_for_auto_gc ()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Aug 19, 2024 at 09:47 UTC
759b453f9f21c5cda483a38f6693dfcbcb680290
1 file changed
+7
-2
t/t7900-maintenance.sh
+7
-2
@@ -967,8 +967,13 @@ test_expect_success '--detach causes maintenance to run in background' '
967
git config set maintenance.loose-objects.auto 1 &&
968
git config set maintenance.incremental-repack.enabled true &&
969
970
- git maintenance run --detach >out 2>&1 &&
971
- test_must_be_empty out
970
+ # The extra file descriptor gets inherited to the child
971
+ # process, and by reading stdout we thus essentially wait for
972
+ # that descriptor to get closed, which indicates that the child
973
+ # is done, too.
974
+ output=$(git maintenance run --detach 2>&1 9>&1) &&
975
+ printf "%s" "$output" >output &&
976
+ test_must_be_empty output
977
)
978
'
979