@@ -868,6 +868,82 @@ def execute(self):
868868 assert any ("Skipping invalid db_update" in msg for msg in caplog .messages )
869869 assert any ("Skipping invalid stats_update" in msg for msg in caplog .messages )
870870
871+ @pytest .mark .parametrize ("auto_download,expected_result_files" , [
872+ (True , {"job-results.json" , "result.data" }), # Default behavior - should download
873+ (False , set ()), # Disabled - should not download results
874+ ])
875+ def test_auto_download_results_behavior (
876+ self ,
877+ tmp_path ,
878+ job_manager_root_dir ,
879+ sleep_mock ,
880+ dummy_backend_foo ,
881+ dummy_backend_bar ,
882+ auto_download ,
883+ expected_result_files ,
884+ ):
885+ """
886+ Test that auto_download_results controls whether job results are downloaded.
887+
888+ This test resembles real usage by running the full job management loop
889+ and verifying the file system outcomes.
890+ """
891+ # Create job manager with specified auto_download setting
892+ job_manager = MultiBackendJobManager (
893+ root_dir = job_manager_root_dir ,
894+ auto_download_results = auto_download
895+ )
896+ job_manager .add_backend ("foo" , connection = dummy_backend_foo .connection )
897+
898+ # Create job definitions
899+ df = pd .DataFrame ({"year" : [2018 , 2019 ]})
900+ job_db_path = tmp_path / "jobs.csv"
901+ job_db = CsvJobDatabase (job_db_path ).initialize_from_df (df )
902+
903+ # Run jobs through the full management loop
904+ run_stats = job_manager .run_jobs (job_db = job_db , start_job = self ._create_year_job )
905+
906+ # Verify jobs completed successfully
907+ assert run_stats == dirty_equals .IsPartialDict (
908+ {
909+ "sleep" : dirty_equals .IsInt (gt = 1 ),
910+ "start_job call" : 2 ,
911+ "job finished" : 2 ,
912+ }
913+ )
914+
915+ # Check final job statuses
916+ final_df = job_db .read ()
917+ assert set (final_df .status ) == {"finished" }
918+ assert set (final_df .id ) == {"job-2018" , "job-2019" }
919+
920+ # Verify the file system state matches our auto_download setting
921+ actual_files = set (p .relative_to (job_manager_root_dir ) for p in job_manager_root_dir .glob ("**/*.*" ))
922+
923+ # All jobs should have metadata files regardless of auto_download setting
924+ expected_metadata_files = {
925+ Path (f"job_{ job_id } " ) / f"job_{ job_id } .json"
926+ for job_id in ["job-2018" , "job-2019" ]
927+ }
928+
929+ # Result files depend on auto_download setting
930+ expected_result_paths = {
931+ Path (f"job_{ job_id } " ) / filename
932+ for job_id in ["job-2018" , "job-2019" ]
933+ for filename in expected_result_files
934+ }
935+
936+ # Verify metadata files exist
937+ for metadata_file in expected_metadata_files :
938+ assert metadata_file in actual_files , f"Metadata file { metadata_file } should always exist"
939+
940+ # Verify result files match our expectation
941+ for result_file in expected_result_paths :
942+ if auto_download :
943+ assert result_file in actual_files , f"Result file { result_file } should exist when auto_download_results=True"
944+ else :
945+ assert result_file not in actual_files , f"Result file { result_file } should not exist when auto_download_results=False"
946+
871947
872948JOB_DB_DF_BASICS = pd .DataFrame (
873949 {
@@ -1906,3 +1982,5 @@ def test_with_job_manager_parameter_column_map(
19061982 "description" : "Process 'increment' (namespace https://remote.test/increment.json) with {'data': 5, 'increment': 200}" ,
19071983 },
19081984 }
1985+
1986+
0 commit comments