Skip to content

Commit 51a0b8a

Browse files
pks-tgitster
authored andcommitted
t7900: exercise detaching via trace2 regions
In t7900, we exercise the `--detach` logic by checking whether the command ended up writing anything to its output or not. This supposedly works because we close stdin, stdout and stderr when daemonizing. But one, it breaks on platforms where daemonize is a no-op, like Windows. And second, that git-maintenance(1) outputs anything at all in these tests is a bug in the first place that we'll fix in a subsequent commit. Introduce a new trace2 region around the detach which allows us to more explicitly check whether the detaching logic was executed. This is a much more direct way to exercise the logic, provides a potentially useful signal to tracing logs and also works alright on platforms which do not have the ability to daemonize. Signed-off-by: Patrick Steinhardt <[email protected]> [jc: dropped a stale in-code comment from a test] Signed-off-by: Junio C Hamano <[email protected]>
1 parent 759b453 commit 51a0b8a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

builtin/gc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,8 +1428,11 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
14281428
free(lock_path);
14291429

14301430
/* Failure to daemonize is ok, we'll continue in foreground. */
1431-
if (opts->detach > 0)
1431+
if (opts->detach > 0) {
1432+
trace2_region_enter("maintenance", "detach", the_repository);
14321433
daemonize();
1434+
trace2_region_leave("maintenance", "detach", the_repository);
1435+
}
14331436

14341437
for (i = 0; !found_selected && i < TASK__COUNT; i++)
14351438
found_selected = tasks[i].selected_order >= 0;

t/t7900-maintenance.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,9 @@ test_expect_success '--no-detach causes maintenance to not run in background' '
947947
git config set maintenance.loose-objects.auto 1 &&
948948
git config set maintenance.incremental-repack.enabled true &&
949949
950-
# We have no better way to check whether or not the task ran in
951-
# the background than to verify whether it output anything. The
952-
# next testcase checks the reverse, making this somewhat safer.
953-
git maintenance run --no-detach >out 2>&1 &&
954-
test_line_count = 1 out
950+
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
951+
git maintenance run --no-detach >out 2>&1 &&
952+
! test_region maintenance detach trace.txt
955953
)
956954
'
957955

@@ -971,9 +969,9 @@ test_expect_success '--detach causes maintenance to run in background' '
971969
# process, and by reading stdout we thus essentially wait for
972970
# that descriptor to get closed, which indicates that the child
973971
# is done, too.
974-
output=$(git maintenance run --detach 2>&1 9>&1) &&
975-
printf "%s" "$output" >output &&
976-
test_must_be_empty output
972+
does_not_matter=$(GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
973+
git maintenance run --detach 9>&1) &&
974+
test_region maintenance detach trace.txt
977975
)
978976
'
979977

0 commit comments

Comments
 (0)