@@ -157,7 +157,11 @@ def test_create_check_status_response(binding_string):
157157 "resumePostUri" :
158158 r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
159159 r"2e2568e7-a906-43bd-8364-c81733c5891e/resume"
160- r"?reason={text}&taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE"
160+ r"?reason={text}&taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE" ,
161+ "restartPostUri" :
162+ r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
163+ r"2e2568e7-a906-43bd-8364-c81733c5891e/restart"
164+ r"?taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE"
161165 }
162166 for key , _ in http_management_payload .items ():
163167 http_management_payload [key ] = replace_stand_in_bits (http_management_payload [key ])
@@ -742,6 +746,49 @@ async def test_post_500_resume(binding_string):
742746 await client .resume (TEST_INSTANCE_ID , raw_reason )
743747
744748
749+ @pytest .mark .asyncio
750+ async def test_restart_with_new_instance_id (binding_string ):
751+ """Test restart calls the HTTP restart endpoint with restartWithNewInstanceId=true."""
752+ new_instance_id = "new-instance-id-1234"
753+
754+ post_mock = MockRequest (
755+ expected_url = f"{ RPC_BASE_URL } instances/{ TEST_INSTANCE_ID } /restart?restartWithNewInstanceId=true" ,
756+ response = [202 , new_instance_id ])
757+
758+ client = DurableOrchestrationClient (binding_string )
759+ client ._post_async_request = post_mock .post
760+
761+ result = await client .restart (TEST_INSTANCE_ID )
762+ assert result == new_instance_id
763+
764+
765+ @pytest .mark .asyncio
766+ async def test_restart_with_same_instance_id (binding_string ):
767+ """Test restart calls the HTTP restart endpoint with restartWithNewInstanceId=false."""
768+ post_mock = MockRequest (
769+ expected_url = f"{ RPC_BASE_URL } instances/{ TEST_INSTANCE_ID } /restart?restartWithNewInstanceId=false" ,
770+ response = [202 , TEST_INSTANCE_ID ])
771+
772+ client = DurableOrchestrationClient (binding_string )
773+ client ._post_async_request = post_mock .post
774+
775+ result = await client .restart (TEST_INSTANCE_ID , restart_with_new_instance_id = False )
776+ assert result == TEST_INSTANCE_ID
777+
778+
779+ @pytest .mark .asyncio
780+ async def test_restart_instance_not_found (binding_string ):
781+ """Test restart raises exception when instance is not found."""
782+ post_mock = MockRequest (
783+ expected_url = f"{ RPC_BASE_URL } instances/{ TEST_INSTANCE_ID } /restart?restartWithNewInstanceId=true" ,
784+ response = [404 , None ])
785+
786+ client = DurableOrchestrationClient (binding_string )
787+ client ._post_async_request = post_mock .post
788+
789+ with pytest .raises (Exception ) as ex :
790+ await client .restart (TEST_INSTANCE_ID )
791+ assert f"No instance with ID '{ TEST_INSTANCE_ID } ' found." in str (ex .value )
745792# Tests for function_invocation_id parameter
746793def test_client_stores_function_invocation_id (binding_string ):
747794 """Test that the client stores the function_invocation_id parameter."""
0 commit comments