Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/codeweaver/engine/chunker/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __enter__(self) -> Self:
Returns:
Self reference for use in with statement
"""
self._start_time = time.time()
self._start_time = time.monotonic()
self._chunk_count = 0
return self

Expand Down Expand Up @@ -115,7 +115,7 @@ def check_timeout(self) -> None:
if self._start_time is None:
return

elapsed = time.time() - self._start_time
elapsed = time.monotonic() - self._start_time
if elapsed > self.settings.chunk_timeout_seconds:
# Log resource limit violation for observability
from pathlib import Path
Expand Down Expand Up @@ -157,7 +157,7 @@ def check_chunk_limit(self) -> None:
limit_value=float(self.settings.max_chunks_per_file),
actual_value=float(self._chunk_count),
extra_context={
"elapsed_seconds": time.time() - self._start_time if self._start_time else 0
"elapsed_seconds": time.monotonic() - self._start_time if self._start_time is not None else 0
},
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
)

Expand Down
45 changes: 11 additions & 34 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from collections.abc import AsyncGenerator, Generator
from pathlib import Path
from typing import TYPE_CHECKING, Any
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import AsyncMock, MagicMock

import pytest

Expand Down Expand Up @@ -534,16 +534,8 @@ def configured_providers(
container.override(VectorStoreProvider, mock_vector_store)
container.override(RerankingProvider, mock_reranking_provider)

call_count = [0] # Use list for mutable counter

def mock_time() -> float:
call_count[0] += 1
# Return monotonically increasing time values (start from a baseline)
return 1000000.0 + call_count[0] * 0.001

with patch("time.time", side_effect=mock_time):
yield
container.clear_overrides()
yield
container.clear_overrides()


# ===========================================================================
Expand Down Expand Up @@ -1025,15 +1017,8 @@ def real_providers(
container.override(VectorStoreProvider, real_vector_store)
container.override(RerankingProvider, real_reranking_provider)

call_count = [0]

def mock_time() -> float:
call_count[0] += 1
return 1000000.0 + call_count[0] * 0.001

with patch("time.time", side_effect=mock_time):
yield
container.clear_overrides()
yield
container.clear_overrides()


# ===========================================================================
Expand Down Expand Up @@ -1221,23 +1206,15 @@ async def get_test_settings() -> CodeWeaverSettingsType:

server._state = state

# Patch time for deterministic behavior if needed
call_count = [0]

def mock_time() -> float:
call_count[0] += 1
return 1000000.0 + call_count[0] * 0.001

with patch("time.time", side_effect=mock_time):
# Resolve indexer from container
indexer = await clean_container.resolve(IndexingService)
# Resolve indexer from container
indexer = await clean_container.resolve(IndexingService)

# Ensure it's using the correct project path
indexer._project_path = project_path
# Ensure it's using the correct project path
indexer._project_path = project_path

await indexer.index_project(force_reindex=True)
await indexer.index_project(force_reindex=True)

yield project_path
yield project_path

# Cleanup: Reset global state
from codeweaver.server import server
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/engine/chunker/test_governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_timeout_enforcement():

with patch("codeweaver.engine.chunker.governance.time") as mock_time:
# Set up time progression: 0.0 at __enter__, 1.5 at check_timeout()
mock_time.time.side_effect = [0.0, 1.5]
mock_time.monotonic.side_effect = [0.0, 1.5]

with pytest.raises(ChunkingTimeoutError, match="exceeded timeout"):
with ResourceGovernor(settings) as governor:
Expand Down
Loading