@@ -199,7 +199,7 @@ async def test_create_job_uses_uuid_and_experiment_dir(tmp_path, monkeypatch):
199199
200200
201201@pytest .mark .asyncio
202- async def test_create_job_retries_after_file_exists_error (tmp_path , monkeypatch ):
202+ async def test_create_job_retries_after_file_exists_error (tmp_path , monkeypatch , caplog ):
203203 for mod in list (importlib .sys .modules .keys ()):
204204 if mod .startswith ("lab." ):
205205 importlib .sys .modules .pop (mod )
@@ -225,10 +225,53 @@ async def flaky_create(job_id, experiment_id):
225225
226226 monkeypatch .setattr (Job , "create" , flaky_create )
227227
228+ caplog .set_level ("WARNING" , logger = "lab.experiment" )
228229 exp = Experiment ("alpha" )
229230 job = await exp .create_job ("TRAIN" )
230231 assert str (job .id ) == "unique-id"
231232 assert attempts ["count" ] == 2
233+ assert "Job.create raised FileExistsError; retrying with new UUID" in caplog .text
234+
235+
236+ @pytest .mark .asyncio
237+ async def test_create_job_retries_with_backoff_for_juicefs (tmp_path , monkeypatch ):
238+ for mod in list (importlib .sys .modules .keys ()):
239+ if mod .startswith ("lab." ):
240+ importlib .sys .modules .pop (mod )
241+
242+ ws = tmp_path / "ws"
243+ ws .mkdir ()
244+ monkeypatch .setenv ("TFL_WORKSPACE_DIR" , str (ws ))
245+ monkeypatch .setenv ("TFL_STORAGE_PROVIDER" , "juicefs" )
246+
247+ from lab .experiment import Experiment
248+ from lab .job import Job
249+
250+ ids = iter (["collision-id" , "unique-id" ])
251+ monkeypatch .setattr ("lab.experiment.uuid.uuid4" , lambda : next (ids ))
252+
253+ original_create = Job .create
254+ attempts = {"count" : 0 }
255+ sleep_calls = {"count" : 0 }
256+
257+ async def flaky_create (job_id , experiment_id ):
258+ attempts ["count" ] += 1
259+ if attempts ["count" ] == 1 :
260+ raise FileExistsError ("simulated duplicate job id" )
261+ return await original_create (job_id , experiment_id )
262+
263+ async def fake_sleep (_ : float ):
264+ sleep_calls ["count" ] += 1
265+
266+ monkeypatch .setattr (Job , "create" , flaky_create )
267+ monkeypatch .setattr ("lab.experiment.asyncio.sleep" , fake_sleep )
268+ monkeypatch .setattr ("lab.experiment.random.uniform" , lambda _a , _b : 0.0 )
269+
270+ exp = Experiment ("alpha" )
271+ job = await exp .create_job ("TRAIN" )
272+ assert str (job .id ) == "unique-id"
273+ assert attempts ["count" ] == 2
274+ assert sleep_calls ["count" ] == 1
232275
233276
234277@pytest .mark .asyncio
0 commit comments