mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-22 16:25:58 +00:00
test(file-sync): patch module-level _monotonic alias instead of shared stdlib time module
Follow-up for salvaged PR #39946: file_sync.py already aliases time.sleep as _sleep specifically to avoid tests mutating the shared stdlib module object. Apply the same convention to the rate-limit clock (_monotonic) and point the new regression test at it.
This commit is contained in:
parent
f9158b818b
commit
8decd39844
2 changed files with 7 additions and 4 deletions
|
|
@ -236,7 +236,7 @@ class TestRateLimiting:
|
|||
from tools.environments import file_sync
|
||||
|
||||
clock = {"t": 1000.0}
|
||||
monkeypatch.setattr(file_sync.time, "monotonic", lambda: clock["t"])
|
||||
monkeypatch.setattr(file_sync, "_monotonic", lambda: clock["t"])
|
||||
|
||||
upload = MagicMock(side_effect=RuntimeError("transport down"))
|
||||
mgr = FileSyncManager(
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ logger = logging.getLogger(__name__)
|
|||
# ``time.sleep`` globally because ``time`` is the module object; under xdist
|
||||
# that lets unrelated background threads inflate retry-test call counts.
|
||||
_sleep = time.sleep
|
||||
# Same rationale for the rate-limit clock: tests patch ``_monotonic``
|
||||
# instead of ``time.monotonic`` on the shared module object.
|
||||
_monotonic = time.monotonic
|
||||
|
||||
_SYNC_INTERVAL_SECONDS = 5.0
|
||||
_FORCE_SYNC_ENV = "HERMES_FORCE_FILE_SYNC"
|
||||
|
|
@ -169,7 +172,7 @@ class FileSyncManager:
|
|||
On failure, state rolls back so the next cycle retries everything.
|
||||
"""
|
||||
if not force and not os.environ.get(_FORCE_SYNC_ENV):
|
||||
now = time.monotonic()
|
||||
now = _monotonic()
|
||||
if now - self._last_sync_time < self._sync_interval:
|
||||
return
|
||||
|
||||
|
|
@ -193,7 +196,7 @@ class FileSyncManager:
|
|||
to_delete = [p for p in self._synced_files if p not in current_remote_paths]
|
||||
|
||||
if not to_upload and not to_delete:
|
||||
self._last_sync_time = time.monotonic()
|
||||
self._last_sync_time = _monotonic()
|
||||
return
|
||||
|
||||
# Snapshot for rollback (only when there's work to do)
|
||||
|
|
@ -227,7 +230,7 @@ class FileSyncManager:
|
|||
self._pushed_hashes.pop(p, None)
|
||||
|
||||
self._synced_files = new_files
|
||||
self._last_sync_time = time.monotonic()
|
||||
self._last_sync_time = _monotonic()
|
||||
|
||||
except Exception as exc:
|
||||
self._synced_files = prev_files
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue