@ -93,3 +93,75 @@ def test_manual_pick_skips_retry_on_errored_state(fake_monitor):
assert task [ ' status ' ] == ' downloading '
def test_monitor_waits_for_post_processing_before_batch_success ( monkeypatch ) :
""" Engine completion is not the same as a successful import.
The monitor should start post - processing when slskd reports a completed
transfer , but the post - processing worker must be the only code path that
reports final success / failure to the batch lifecycle .
"""
monkeypatch . setattr ( dm , ' _make_context_key ' , lambda u , f : f " { u } :: { f } " )
monkeypatch . setattr ( dm . WebUIDownloadMonitor , ' _validate_worker_counts ' , lambda self : None )
submitted = [ ]
completions = [ ]
class FakeExecutor :
def submit ( self , func , task_id , batch_id ) :
submitted . append ( ( func , task_id , batch_id ) )
def fake_post_processing_worker ( task_id , batch_id ) :
return None
monkeypatch . setattr ( dm , ' missing_download_executor ' , FakeExecutor ( ) )
monkeypatch . setattr ( dm , ' _run_post_processing_worker ' , fake_post_processing_worker )
monkeypatch . setattr (
dm ,
' _on_download_completed ' ,
lambda batch_id , task_id , success : completions . append ( ( batch_id , task_id , success ) ) ,
)
with dm . tasks_lock :
previous_tasks = dict ( dm . download_tasks )
previous_batches = dict ( dm . download_batches )
dm . download_tasks . clear ( )
dm . download_batches . clear ( )
dm . download_tasks [ ' task-1 ' ] = {
' track_info ' : { ' name ' : ' Test Track ' } ,
' username ' : ' Pinasound ' ,
' filename ' : r ' @@tmllb \ Music \ Album \ 01. Track.flac ' ,
' status ' : ' downloading ' ,
' download_id ' : ' download-1 ' ,
' status_change_time ' : time . time ( ) ,
}
dm . download_batches [ ' batch-1 ' ] = { ' queue ' : [ ' task-1 ' ] }
try :
monitor = dm . WebUIDownloadMonitor ( )
monitor . monitoring = True
monitor . monitored_batches . add ( ' batch-1 ' )
monkeypatch . setattr (
monitor ,
' _get_live_transfers ' ,
lambda : {
r ' Pinasound::@@tmllb \ Music \ Album \ 01. Track.flac ' : {
' state ' : ' Completed, Succeeded ' ,
' size ' : 100 ,
' bytesTransferred ' : 100 ,
}
} ,
)
monitor . _check_all_downloads ( )
assert submitted == [ ( fake_post_processing_worker , ' task-1 ' , ' batch-1 ' ) ]
assert completions == [ ]
assert dm . download_tasks [ ' task-1 ' ] [ ' status ' ] == ' post_processing '
finally :
with dm . tasks_lock :
dm . download_tasks . clear ( )
dm . download_tasks . update ( previous_tasks )
dm . download_batches . clear ( )
dm . download_batches . update ( previous_batches )