Merge branch 'ps/maintenance-detach-fix-more'

A tests for "git maintenance" that were broken on Windows have been
corrected.

* ps/maintenance-detach-fix-more:
  builtin/maintenance: fix loose objects task emitting pack hash
  t7900: exercise detaching via trace2 regions
  t7900: fix flaky test due to leaking background job
This commit is contained in:
Junio C Hamano
2024-08-26 11:32:20 -07:00
2 changed files with 35 additions and 7 deletions

View File

@ -1160,6 +1160,12 @@ static int pack_loose(struct maintenance_run_opts *opts)
pack_proc.in = -1;
/*
* git-pack-objects(1) ends up writing the pack hash to stdout, which
* we do not care for.
*/
pack_proc.out = -1;
if (start_command(&pack_proc)) {
error(_("failed to start 'git pack-objects' process"));
return 1;
@ -1429,8 +1435,11 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
free(lock_path);
/* Failure to daemonize is ok, we'll continue in foreground. */
if (opts->detach > 0)
if (opts->detach > 0) {
trace2_region_enter("maintenance", "detach", the_repository);
daemonize();
trace2_region_leave("maintenance", "detach", the_repository);
}
for (i = 0; !found_selected && i < TASK__COUNT; i++)
found_selected = tasks[i].selected_order >= 0;

View File

@ -947,11 +947,9 @@ test_expect_success '--no-detach causes maintenance to not run in background' '
git config set maintenance.loose-objects.auto 1 &&
git config set maintenance.incremental-repack.enabled true &&
# We have no better way to check whether or not the task ran in
# the background than to verify whether it output anything. The
# next testcase checks the reverse, making this somewhat safer.
git maintenance run --no-detach >out 2>&1 &&
test_line_count = 1 out
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
git maintenance run --no-detach >out 2>&1 &&
! test_region maintenance detach trace.txt
)
'
@ -967,7 +965,28 @@ test_expect_success '--detach causes maintenance to run in background' '
git config set maintenance.loose-objects.auto 1 &&
git config set maintenance.incremental-repack.enabled true &&
git maintenance run --detach >out 2>&1 &&
# The extra file descriptor gets inherited to the child
# process, and by reading stdout we thus essentially wait for
# that descriptor to get closed, which indicates that the child
# is done, too.
does_not_matter=$(GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
git maintenance run --detach 9>&1) &&
test_region maintenance detach trace.txt
)
'
test_expect_success 'repacking loose objects is quiet' '
test_when_finished "rm -rf repo" &&
git init repo &&
(
cd repo &&
test_commit something &&
git config set maintenance.gc.enabled false &&
git config set maintenance.loose-objects.enabled true &&
git config set maintenance.loose-objects.auto 1 &&
git maintenance run --quiet >out 2>&1 &&
test_must_be_empty out
)
'