Skip to content

Commit 2775d8b

Browse files
pks-tgitster
authored andcommitted
t7900: fix flaky "maintenance.strategy" test
One of our tests for whether "maintenance.strategy" is being respected in t7900 is flaky in our CI systems: + GIT_TRACE2_EVENT=/tmp/test-output/trash directory.t7900-maintenance/repo/trace2.txt git -c maintenance.strategy=incremental maintenance run --quiet + test_maintenance_tasks trace2.txt + cat + sed -ne s/.*"region_enter".*"category":"maintenance\([^"]*\)".*"label":"\([^"][^"]*\)".*/\2\1/p trace2.txt + test_cmp expect actual + test 2 -ne 2 + eval /usr/bin/diff -u "$@" + /usr/bin/diff -u expect actual --- expect 2026-08-07 06:20:51.388322602 +0000 +++ actual 2026-08-07 06:20:51.388322602 +0000 @@ -1,2 +0,0 @@ -gc foreground -gc When running with the "incremental" strategy, we expect two git-gc(1) tasks to have been executed, but sometimes the test simply doesn't execute any of those tasks. A first hunch may be that maybe the disk-state is sometimes different and thus we decide not to run maintenance. But git-maintenance(1) doesn't run with the "--auto" switch, so we should execute those tasks regardless of the on-disk state. But there's a second condition that may cause us to not execute tasks, namely when the "maintenance.lock" file exists due to a concurrently running git-maintenance(1) process. We usually disable auto-maintenance from detaching in our test suite to avoid exactly these kinds of race conditions by exporting `GIT_TEST_MAINT_AUTO_DETACH=false`. But in t7900 we unset "GIT_TEST_MAINT_AUTO_DETACH" and thus enable the auto-detach logic. The intent of this is to exercise git-maintenance(1) closer to how it would run in a real-world scenario, but it does cause us to race when the detached maintenance job that was triggered by `test_commit()` lives long enough. We could trivially fix this race by disabling auto-maintenance for this specific test. But that doesn't fix this class of races in this test suite: while I haven't seen any of the other tests fail in the same way, a bunch of them have this race, as well. Instead, let's retain "GIT_TEST_MAINT_AUTO_DETACH" and only unset it as required. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5fb9b8b commit 2775d8b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

t/t7900-maintenance.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ test_description='git maintenance builtin'
77
GIT_TEST_COMMIT_GRAPH=0
88
GIT_TEST_MULTI_PACK_INDEX=0
99

10-
# Ensure that auto-maintenance detaches as usual.
11-
sane_unset GIT_TEST_MAINT_AUTO_DETACH
12-
1310
test_lazy_prereq XMLLINT '
1411
xmllint --version
1512
'
@@ -65,6 +62,7 @@ test_expect_success 'maintenance.auto config option' '
6562
git init repo &&
6663
(
6764
cd repo &&
65+
sane_unset GIT_TEST_MAINT_AUTO_DETACH &&
6866
6967
GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
7068
test_subcommand git maintenance run --auto --quiet --detach <default &&
@@ -84,6 +82,7 @@ test_expect_success 'gc.auto config option' '
8482
git init repo &&
8583
(
8684
cd repo &&
85+
sane_unset GIT_TEST_MAINT_AUTO_DETACH &&
8786
8887
GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
8988
test_subcommand git maintenance run --auto --quiet --detach <default &&
@@ -101,6 +100,7 @@ test_expect_success 'maintenance.auto overrides gc.auto' '
101100
git init repo &&
102101
(
103102
cd repo &&
103+
sane_unset GIT_TEST_MAINT_AUTO_DETACH &&
104104
105105
git config set maintenance.auto false &&
106106
git config set gc.auto 1 &&

0 commit comments

Comments
 (0)