2828 get_job_provisioning_data ,
2929 get_run_spec ,
3030)
31+ from dstack ._internal .utils import common
3132
3233pytestmark = pytest .mark .usefixtures ("image_config_mock" )
3334
@@ -72,10 +73,14 @@ async def make_run(
7273class TestProcessRuns :
7374 @pytest .mark .asyncio
7475 @pytest .mark .parametrize ("test_db" , ["sqlite" , "postgres" ], indirect = True )
76+ @patch (
77+ "dstack._internal.utils.common.get_current_datetime" ,
78+ return_value = datetime .datetime (2024 , 1 , 1 , 12 , 0 , 0 , tzinfo = datetime .timezone .utc ),
79+ )
7580 async def test_submitted_to_provisioning (self , test_db , session : AsyncSession ):
7681 run = await make_run (session , status = RunStatus .SUBMITTED )
7782 await create_job (session = session , run = run , status = JobStatus .PROVISIONING )
78- current_time = datetime . datetime . now ( datetime . timezone . utc )
83+ current_time = common . get_current_datetime ( )
7984
8085 expected_duration = (
8186 current_time - run .submitted_at .replace (tzinfo = datetime .timezone .utc )
@@ -91,9 +96,7 @@ async def test_submitted_to_provisioning(self, test_db, session: AsyncSession):
9196 assert args [1 ] == run .project .name
9297 assert args [2 ] == "service"
9398 # Assert the duration is close to our expected duration (within 0.05 second tolerance)
94- assert abs (args [0 ] - expected_duration ) < 0.05 , (
95- f"Expected duration ~{ expected_duration :.3f} s, got { args [0 ]:.3f} s"
96- )
99+ assert args [0 ] == expected_duration
97100
98101 await session .refresh (run )
99102 assert run .status == RunStatus .PROVISIONING
@@ -233,11 +236,15 @@ async def test_pending_to_submitted(self, test_db, session: AsyncSession):
233236class TestProcessRunsReplicas :
234237 @pytest .mark .asyncio
235238 @pytest .mark .parametrize ("test_db" , ["sqlite" , "postgres" ], indirect = True )
239+ @patch (
240+ "dstack._internal.utils.common.get_current_datetime" ,
241+ return_value = datetime .datetime (2024 , 1 , 1 , 12 , 0 , 0 , tzinfo = datetime .timezone .utc ),
242+ )
236243 async def test_submitted_to_provisioning_if_any (self , test_db , session : AsyncSession ):
237244 run = await make_run (session , status = RunStatus .SUBMITTED , replicas = 2 )
238245 await create_job (session = session , run = run , status = JobStatus .SUBMITTED , replica_num = 0 )
239246 await create_job (session = session , run = run , status = JobStatus .PROVISIONING , replica_num = 1 )
240- current_time = datetime . datetime . now ( datetime . timezone . utc )
247+ current_time = common . get_current_datetime ( )
241248
242249 expected_duration = (
243250 current_time - run .submitted_at .replace (tzinfo = datetime .timezone .utc )
@@ -253,10 +260,7 @@ async def test_submitted_to_provisioning_if_any(self, test_db, session: AsyncSes
253260 assert args [1 ] == run .project .name
254261 assert args [2 ] == "service"
255262 assert isinstance (args [0 ], float )
256- # Assert the duration is close to our expected duration (within 0.05 second tolerance)
257- assert abs (args [0 ] - expected_duration ) < 0.05 , (
258- f"Expected duration ~{ expected_duration :.3f} s, got { args [0 ]:.3f} s"
259- )
263+ assert args [0 ] == expected_duration
260264
261265 await session .refresh (run )
262266 assert run .status == RunStatus .PROVISIONING
0 commit comments