Skip to content

Commit 958002b

Browse files
Byroncodex
andcommitted
test: Disable automatic maintenance in remote timeout tests
<!-- agent --> Ubuntu CI reported FileNotFoundError for maintenance.lock while running test_timeout_funcs. The test performs normal pull/fetch calls before its forced timeouts, and Git can launch detached automatic maintenance from those operations. Maintenance can then race with the fixture's recursive removal of the temporary repository, removing a lock file after cleanup has enumerated it. Disable maintenance.auto in this test's temporary repository and set gc.auto to zero for older Git versions that use automatic garbage collection. This removes background housekeeping unrelated to the timeout assertions without weakening repository cleanup or changing library behavior. Use mock.patch.object for the global forced termination status so an assertion failure cannot leak the override into subsequent tests. Validation: Git Trace2 recorded three detached maintenance launches in the original test and none with the fix. The timeout test then passed 20 consecutive runs locally on macOS. Ruff lint and formatting checks and git diff --check passed. The original Ubuntu cleanup exception was not reproduced locally; tracing verified removal of the suspected race source. Assisted-by: GPT 6.0 Co-authored-by: GPT 6.0 <codex@openai.com>
1 parent 415c211 commit 958002b

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

test/test_remote.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,14 +1090,16 @@ def test_fetch_unsafe_branch_name(self, rw_repo, remote_repo):
10901090
class TestTimeouts(TestBase):
10911091
@with_rw_repo("HEAD", bare=False)
10921092
def test_timeout_funcs(self, repo):
1093+
# Maintenance may outlive a timed-out fetch and race with fixture cleanup.
1094+
with repo.config_writer() as config:
1095+
config.set_value("maintenance", "auto", False)
1096+
config.set_value("gc", "auto", 0) # Older Git versions use auto-gc.
1097+
10931098
# Force error code to prevent a race condition if the python thread is slow.
1094-
default = Git.AutoInterrupt._status_code_if_terminate
1095-
Git.AutoInterrupt._status_code_if_terminate = -15
1096-
for function in ["pull", "fetch"]: # Can't get push to time out.
1097-
f = getattr(repo.remotes.origin, function)
1098-
assert f is not None # Make sure these functions exist.
1099-
_ = f() # Make sure the function runs.
1100-
with pytest.raises(GitCommandError, match="kill_after_timeout=0 s"):
1101-
f(kill_after_timeout=0)
1102-
1103-
Git.AutoInterrupt._status_code_if_terminate = default
1099+
with mock.patch.object(Git.AutoInterrupt, "_status_code_if_terminate", -15):
1100+
for function in ["pull", "fetch"]: # Can't get push to time out.
1101+
f = getattr(repo.remotes.origin, function)
1102+
assert f is not None # Make sure these functions exist.
1103+
_ = f() # Make sure the function runs.
1104+
with pytest.raises(GitCommandError, match="kill_after_timeout=0 s"):
1105+
f(kill_after_timeout=0)

0 commit comments

Comments
 (0)