11from __future__ import annotations
22
33from datetime import datetime , timedelta , timezone
4- from time import sleep
54
65import pytest
76from fastapi .testclient import TestClient
2322)
2423
2524
26- def test_heartbeat (normal_user_client : TestClient , valid_job_id : int ):
25+ def test_heartbeat (frozen_time , normal_user_client : TestClient , valid_job_id : int ):
2726 search_body = {
2827 "search" : [{"parameter" : "JobID" , "operator" : "eq" , "value" : valid_job_id }]
2928 }
@@ -60,7 +59,7 @@ def test_heartbeat(normal_user_client: TestClient, valid_job_id: int):
6059 )
6160 r .raise_for_status ()
6261
63- sleep ( 1 )
62+ frozen_time . tick ( delta = timedelta ( seconds = 1 ) )
6463 # Send another heartbeat and check that a Kill job command was set
6564 payload = {valid_job_id : {"Vsize" : 1235 }}
6665 r = normal_user_client .patch ("/api/jobs/heartbeat" , json = payload )
@@ -74,7 +73,7 @@ def test_heartbeat(normal_user_client: TestClient, valid_job_id: int):
7473 assert commands [0 ]["command" ] == "Kill" , (
7574 f"Wrong job command received, should be 'Kill' but got { commands [0 ]= } "
7675 )
77- sleep ( 1 )
76+ frozen_time . tick ( delta = timedelta ( seconds = 1 ) )
7877
7978 # Send another heartbeat and check the job commands are empty
8079 payload = {valid_job_id : {"Vsize" : 1234 }}
@@ -87,6 +86,7 @@ def test_heartbeat(normal_user_client: TestClient, valid_job_id: int):
8786
8887
8988def test_multiple_jobs_receive_independent_kill_commands (
89+ frozen_time ,
9090 normal_user_client : TestClient ,
9191 valid_job_ids : list [int ],
9292):
@@ -105,7 +105,7 @@ def test_multiple_jobs_receive_independent_kill_commands(
105105 )
106106 r .raise_for_status ()
107107
108- sleep ( 1 )
108+ frozen_time . tick ( delta = timedelta ( seconds = 1 ) )
109109
110110 r = normal_user_client .patch (
111111 "/api/jobs/heartbeat" ,
@@ -118,7 +118,7 @@ def test_multiple_jobs_receive_independent_kill_commands(
118118 assert {cmd ["job_id" ] for cmd in commands } == set (valid_job_ids )
119119 assert {cmd ["command" ] for cmd in commands } == {"Kill" }
120120
121- sleep ( 1 )
121+ frozen_time . tick ( delta = timedelta ( seconds = 1 ) )
122122
123123 r = normal_user_client .patch (
124124 "/api/jobs/heartbeat" ,
@@ -130,6 +130,7 @@ def test_multiple_jobs_receive_independent_kill_commands(
130130
131131
132132def test_non_killed_status_does_not_create_command (
133+ frozen_time ,
133134 normal_user_client : TestClient ,
134135 valid_job_id : int ,
135136):
@@ -147,7 +148,7 @@ def test_non_killed_status_does_not_create_command(
147148 )
148149 r .raise_for_status ()
149150
150- sleep ( 1 )
151+ frozen_time . tick ( delta = timedelta ( seconds = 1 ) )
151152
152153 r = normal_user_client .patch (
153154 "/api/jobs/heartbeat" ,
@@ -159,6 +160,7 @@ def test_non_killed_status_does_not_create_command(
159160
160161
161162def test_deleted_creates_kill_command (
163+ frozen_time ,
162164 normal_user_client : TestClient ,
163165 valid_job_id : int ,
164166):
@@ -176,7 +178,7 @@ def test_deleted_creates_kill_command(
176178 )
177179 r .raise_for_status ()
178180
179- sleep ( 1 )
181+ frozen_time . tick ( delta = timedelta ( seconds = 1 ) )
180182
181183 r = normal_user_client .patch (
182184 "/api/jobs/heartbeat" ,
@@ -189,7 +191,7 @@ def test_deleted_creates_kill_command(
189191 assert commands [0 ]["job_id" ] == valid_job_id
190192 assert commands [0 ]["command" ] == "Kill"
191193
192- sleep ( 1 )
194+ frozen_time . tick ( delta = timedelta ( seconds = 1 ) )
193195
194196 r = normal_user_client .patch (
195197 "/api/jobs/heartbeat" ,
0 commit comments