9
9
from multiprocessing .process import BaseProcess
10
10
from multiprocessing .synchronize import Barrier , Event
11
11
from typing import Any , Generic , Literal
12
+ from unittest .mock import patch
12
13
13
14
import pytest
14
15
from pydantic import Field
@@ -48,6 +49,23 @@ class MockRequestTimings(MeasuredRequestTimings):
48
49
timings_type : Literal ["mock" ] = Field (default = "mock" )
49
50
50
51
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
+
51
69
class MockBackend (BackendInterface ):
52
70
"""Mock backend for testing worker group functionality."""
53
71
@@ -67,6 +85,7 @@ def processes_limit(self) -> int | None:
67
85
def requests_limit (self ) -> int | None :
68
86
return self ._requests_limit
69
87
88
+ @property
70
89
def info (self ) -> dict [str , Any ]:
71
90
return {"type" : "mock" }
72
91
@@ -249,6 +268,7 @@ def test_invalid_initialization_missing(self):
249
268
@pytest .mark .smoke
250
269
@async_timeout (10 )
251
270
@pytest .mark .asyncio
271
+ @patch .object (time , "time" , mock_time .time )
252
272
async def test_lifecycle (self , valid_instances : tuple [WorkerProcessGroup , dict ]): # noqa: C901, PLR0912
253
273
"""Test the lifecycle methods of WorkerProcessGroup."""
254
274
instance , constructor_args = valid_instances
0 commit comments