Skip to content

Commit 5032e9e

Browse files
committed
Patch time.time in workgroup lifecycle test
Signed-off-by: Samuel Monson <[email protected]>
1 parent 544c888 commit 5032e9e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/unit/scheduler/test_worker_group.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from multiprocessing.process import BaseProcess
1010
from multiprocessing.synchronize import Barrier, Event
1111
from typing import Any, Generic, Literal
12+
from unittest.mock import patch
1213

1314
import pytest
1415
from pydantic import Field
@@ -48,6 +49,23 @@ class MockRequestTimings(MeasuredRequestTimings):
4849
timings_type: Literal["mock"] = Field(default="mock")
4950

5051

52+
class MockTime:
53+
"""Deterministic time mock for testing."""
54+
55+
def __init__(self, start_time: float = 1000.0):
56+
self.current_time = start_time
57+
self.increment = 0.1
58+
59+
def time(self) -> float:
60+
"""Return current mock time and increment for next call."""
61+
current = self.current_time
62+
self.current_time += self.increment
63+
return current
64+
65+
66+
mock_time = MockTime()
67+
68+
5169
class MockBackend(BackendInterface):
5270
"""Mock backend for testing worker group functionality."""
5371

@@ -67,6 +85,7 @@ def processes_limit(self) -> int | None:
6785
def requests_limit(self) -> int | None:
6886
return self._requests_limit
6987

88+
@property
7089
def info(self) -> dict[str, Any]:
7190
return {"type": "mock"}
7291

@@ -249,6 +268,7 @@ def test_invalid_initialization_missing(self):
249268
@pytest.mark.smoke
250269
@async_timeout(10)
251270
@pytest.mark.asyncio
271+
@patch.object(time, "time", mock_time.time)
252272
async def test_lifecycle(self, valid_instances: tuple[WorkerProcessGroup, dict]): # noqa: C901, PLR0912
253273
"""Test the lifecycle methods of WorkerProcessGroup."""
254274
instance, constructor_args = valid_instances

0 commit comments

Comments
 (0)