File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,15 +177,17 @@ def run_update(strategy: str):
177177
178178 prepare_temp_dir ()
179179
180- download_url = get_download_url ()
181- _ensure_disk_space (download_url , parallel = strategy == "PARALLEL" )
180+ try :
181+ download_url = get_download_url ()
182+ _ensure_disk_space (download_url , parallel = strategy == "PARALLEL" )
182183
183- index_file = _download_verified_index ()
184+ index_file = _download_verified_index ()
184185
185- extract_index (index_file )
186+ extract_index (index_file )
186187
187- logging .info ("Activating new index" )
188- index .activate (os .path .join (config .TEMP_DIR , "photon_data" ))
189- clear_temp_dir ()
188+ logging .info ("Activating new index" )
189+ index .activate (os .path .join (config .TEMP_DIR , "photon_data" ))
190190
191- logging .info ("Update pipeline completed successfully." )
191+ logging .info ("Update pipeline completed successfully." )
192+ finally :
193+ clear_temp_dir ()
Original file line number Diff line number Diff line change @@ -321,6 +321,28 @@ def boom():
321321 update .run_update ("SEQUENTIAL" )
322322
323323
324+ def test_run_update_clears_temp_dir_on_failure (fake_dirs : Path , monkeypatch : pytest .MonkeyPatch ):
325+ monkeypatch .setattr (config , "SKIP_MD5_CHECK" , True )
326+ _make_pipeline_patches (monkeypatch )
327+
328+ cleared = {"n" : 0 }
329+
330+ def fake_clear ():
331+ cleared ["n" ] += 1
332+
333+ monkeypatch .setattr (update , "clear_temp_dir" , fake_clear )
334+
335+ def boom ():
336+ raise update .DownloadError ("download died" )
337+
338+ monkeypatch .setattr (update , "download_index" , boom )
339+
340+ with pytest .raises (update .DownloadError , match = "download died" ):
341+ update .run_update ("SEQUENTIAL" )
342+
343+ assert cleared ["n" ] == 1
344+
345+
324346def test_run_update_checksum_mismatch_prevents_activation (fake_dirs : Path , monkeypatch : pytest .MonkeyPatch ):
325347 monkeypatch .setattr (config , "SKIP_MD5_CHECK" , False )
326348 _make_pipeline_patches (monkeypatch )
You can’t perform that action at this time.
0 commit comments