From d048879cbbf51a37b93e2524ca4c060649893529 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 5 Dec 2026 19:20:35 -0600 Subject: [PATCH] tests(fix[sync]): Default VCSPULL_SYNC_TIMEOUT_SECONDS=30 in pytest why: On heavily contended hosts (load average 50-80), libvcs's 10-16 sequential hg Python spawns per HgSync.update_repo() call exceed both the 10s CLI default in test_sync_errored_hg_repo and the 15s literal in test_hg_configured_remote_reaches_native_sync. what: - Default VCSPULL_SYNC_TIMEOUT_SECONDS=30 alongside VCSPULL_JOBS=1 in tests/conftest.py when unset in the caller environment - Route test_hg_configured_remote_reaches_native_sync through _resolve_repo_timeout(None) instead of a hardcoded literal - Seed upstream in test_hg_configured_remote_reaches_native_sync with shutil.copytree and hg commit -A to drop redundant setup hg spawns --- tests/conftest.py | 9 ++++++--- tests/test_sync.py | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b64bf791..b88d7ca6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,13 +2,14 @@ from __future__ import annotations -from typing import TYPE_CHECKING +import os +import typing as t import pytest from syrupy.extensions.json import JSONSnapshotExtension from syrupy.extensions.single_file import SingleFileSnapshotExtension, WriteMode -if TYPE_CHECKING: +if t.TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion @@ -34,5 +35,7 @@ def snapshot_yaml(snapshot: SnapshotAssertion) -> SnapshotAssertion: @pytest.fixture(autouse=True) def _default_serial_sync_jobs(monkeypatch: pytest.MonkeyPatch) -> None: - """Default ``VCSPULL_JOBS=1`` so sequential CLI tests stay deterministic.""" + """Default ``VCSPULL_JOBS=1`` and a 30s sync budget for contended test hosts.""" monkeypatch.setenv("VCSPULL_JOBS", "1") + if "VCSPULL_SYNC_TIMEOUT_SECONDS" not in os.environ: + monkeypatch.setenv("VCSPULL_SYNC_TIMEOUT_SECONDS", "30") diff --git a/tests/test_sync.py b/tests/test_sync.py index f50dbe2b..afee6b1e 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -4,6 +4,7 @@ import json import logging +import shutil import subprocess import textwrap import typing as t @@ -22,7 +23,12 @@ from vcspull._internal.config_reader import ConfigReader from vcspull.cli import cli -from vcspull.cli.sync import _looks_like_branch_error, sync, update_repo +from vcspull.cli.sync import ( + _looks_like_branch_error, + _resolve_repo_timeout, + sync, + update_repo, +) from vcspull.config import ( detect_git_depth, detect_git_shallow, @@ -870,11 +876,10 @@ def test_hg_configured_remote_reaches_native_sync( """Loaded Mercurial paths retain pull selection and separate push URLs.""" from vcspull._internal.sync_process import run_sync_process + shutil.copytree(hg_repo.path, tmp_path / "upstream") upstream = HgSync(url=hg_repo.url, path=tmp_path / "upstream") - upstream.obtain() (upstream.path / "next").write_text("new upstream revision\n") - upstream.run(["add", "next"]) - upstream.run(["commit", "-m", "advance upstream"]) + upstream.run(["commit", "-A", "-m", "advance upstream"]) expected = upstream.get_revision() push_url = (tmp_path / "push-only").as_uri() config = tmp_path / "repos.yaml" @@ -899,7 +904,10 @@ def test_hg_configured_remote_reaches_native_sync( entry = load_configs([config])[0] if worker: outcome = run_sync_process( - entry, progress_callback=lambda *args: None, timeout=15, is_human=False + entry, + progress_callback=lambda *args: None, + timeout=_resolve_repo_timeout(None), + is_human=False, ) assert outcome.status == "synced", outcome.error else: