@@ -528,3 +528,80 @@ async def test_load_offline_run_is_sync_only():
528528
529529 with pytest .raises (PolyaxonClientException ):
530530 await AsyncRunClient .load_offline_run ("/tmp/run" )
531+
532+
533+ @pytest .mark .asyncio
534+ async def test_restart_routes_to_copy_when_copy_flag_set ():
535+ patch_settings ()
536+ sdk_client = AsyncPolyaxonClientMock ()
537+ response = make_run (name = "restarted" )
538+ sdk_client .runs_v1 .copy_run = AsyncMock (return_value = response )
539+ sdk_client .runs_v1 .restart_run = AsyncMock ()
540+ client = make_client (sdk_client )
541+
542+ result = await client .restart (copy = True , name = "restarted" )
543+
544+ assert result is response
545+ assert sdk_client .runs_v1 .copy_run .call_count == 1
546+ assert sdk_client .runs_v1 .restart_run .call_count == 0
547+ assert "async_req" not in sdk_client .runs_v1 .copy_run .call_args [1 ]
548+
549+
550+ @pytest .mark .asyncio
551+ async def test_restart_routes_to_restart_when_copy_not_set ():
552+ patch_settings ()
553+ sdk_client = AsyncPolyaxonClientMock ()
554+ response = make_run (name = "restarted" )
555+ sdk_client .runs_v1 .restart_run = AsyncMock (return_value = response )
556+ sdk_client .runs_v1 .copy_run = AsyncMock ()
557+ client = make_client (sdk_client )
558+
559+ result = await client .restart (name = "restarted" )
560+
561+ assert result is response
562+ assert sdk_client .runs_v1 .restart_run .call_count == 1
563+ assert sdk_client .runs_v1 .copy_run .call_count == 0
564+ assert "async_req" not in sdk_client .runs_v1 .restart_run .call_args [1 ]
565+
566+
567+ @pytest .mark .asyncio
568+ async def test_resume_awaits_resume_run_with_built_body ():
569+ patch_settings ()
570+ sdk_client = AsyncPolyaxonClientMock ()
571+ response = make_run (name = "resumed" )
572+ sdk_client .runs_v1 .resume_run = AsyncMock (return_value = response )
573+ client = make_client (sdk_client )
574+
575+ result = await client .resume (name = "resumed" )
576+
577+ assert result is response
578+ assert sdk_client .runs_v1 .resume_run .call_count == 1
579+ assert "async_req" not in sdk_client .runs_v1 .resume_run .call_args [1 ]
580+
581+
582+ @pytest .mark .asyncio
583+ async def test_log_succeeded_awaits_create_run_status_via_log_status ():
584+ patch_settings ()
585+ sdk_client = AsyncPolyaxonClientMock ()
586+ sdk_client .runs_v1 .create_run_status = AsyncMock (return_value = None )
587+ client = make_client (sdk_client )
588+ client ._run_data = make_run (status = V1Statuses .RUNNING )
589+
590+ await client .log_succeeded ()
591+
592+ assert sdk_client .runs_v1 .create_run_status .call_count == 1
593+ body = sdk_client .runs_v1 .create_run_status .call_args [1 ]["body" ]
594+ assert body ["condition" ].type == V1Statuses .SUCCEEDED
595+
596+
597+ @pytest .mark .asyncio
598+ async def test_log_end_status_short_circuits_when_already_done ():
599+ patch_settings ()
600+ sdk_client = AsyncPolyaxonClientMock ()
601+ sdk_client .runs_v1 .create_run_status = AsyncMock ()
602+ client = make_client (sdk_client )
603+ client ._run_data = make_run (status = V1Statuses .SUCCEEDED )
604+
605+ await client .log_failed ()
606+
607+ assert sdk_client .runs_v1 .create_run_status .call_count == 0
0 commit comments