@@ -156,7 +156,11 @@ def test_create_check_status_response(binding_string):
156156 "resumePostUri" :
157157 r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
158158 r"2e2568e7-a906-43bd-8364-c81733c5891e/resume"
159- r"?reason={text}&taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE"
159+ r"?reason={text}&taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE" ,
160+ "restartPostUri" :
161+ r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
162+ r"2e2568e7-a906-43bd-8364-c81733c5891e/restart"
163+ r"?taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE"
160164 }
161165 for key , _ in http_management_payload .items ():
162166 http_management_payload [key ] = replace_stand_in_bits (http_management_payload [key ])
@@ -739,3 +743,75 @@ async def test_post_500_resume(binding_string):
739743
740744 with pytest .raises (Exception ):
741745 await client .resume (TEST_INSTANCE_ID , raw_reason )
746+
747+
748+ @pytest .mark .asyncio
749+ async def test_restart_with_new_instance_id (binding_string ):
750+ """Test restart creates a new instance with a new ID by default."""
751+ orchestrator_name = "MyOrchestrator"
752+ original_input = {"key" : "value" }
753+ new_instance_id = "new-instance-id-1234"
754+
755+ get_mock = MockRequest (
756+ expected_url = f"{ RPC_BASE_URL } instances/{ TEST_INSTANCE_ID } ?showInput=True" ,
757+ response = [200 , dict (
758+ name = orchestrator_name ,
759+ instanceId = TEST_INSTANCE_ID ,
760+ createdTime = TEST_CREATED_TIME ,
761+ lastUpdatedTime = TEST_LAST_UPDATED_TIME ,
762+ runtimeStatus = "Completed" ,
763+ input = original_input )])
764+
765+ post_mock = MockRequest (
766+ expected_url = f"{ RPC_BASE_URL } orchestrators/{ orchestrator_name } " ,
767+ response = [202 , {"id" : new_instance_id }])
768+
769+ client = DurableOrchestrationClient (binding_string )
770+ client ._get_async_request = get_mock .get
771+ client ._post_async_request = post_mock .post
772+
773+ result = await client .restart (TEST_INSTANCE_ID )
774+ assert result == new_instance_id
775+
776+
777+ @pytest .mark .asyncio
778+ async def test_restart_with_same_instance_id (binding_string ):
779+ """Test restart reuses the original instance ID when restartWithNewInstanceId is False."""
780+ orchestrator_name = "MyOrchestrator"
781+ original_input = {"key" : "value" }
782+
783+ get_mock = MockRequest (
784+ expected_url = f"{ RPC_BASE_URL } instances/{ TEST_INSTANCE_ID } ?showInput=True" ,
785+ response = [200 , dict (
786+ name = orchestrator_name ,
787+ instanceId = TEST_INSTANCE_ID ,
788+ createdTime = TEST_CREATED_TIME ,
789+ lastUpdatedTime = TEST_LAST_UPDATED_TIME ,
790+ runtimeStatus = "Completed" ,
791+ input = original_input )])
792+
793+ post_mock = MockRequest (
794+ expected_url = f"{ RPC_BASE_URL } orchestrators/{ orchestrator_name } /{ TEST_INSTANCE_ID } " ,
795+ response = [202 , {"id" : TEST_INSTANCE_ID }])
796+
797+ client = DurableOrchestrationClient (binding_string )
798+ client ._get_async_request = get_mock .get
799+ client ._post_async_request = post_mock .post
800+
801+ result = await client .restart (TEST_INSTANCE_ID , restart_with_new_instance_id = False )
802+ assert result == TEST_INSTANCE_ID
803+
804+
805+ @pytest .mark .asyncio
806+ async def test_restart_instance_not_found (binding_string ):
807+ """Test restart raises exception when instance is not found."""
808+ get_mock = MockRequest (
809+ expected_url = f"{ RPC_BASE_URL } instances/{ TEST_INSTANCE_ID } ?showInput=True" ,
810+ response = [404 , dict (createdTime = None , lastUpdatedTime = None )])
811+
812+ client = DurableOrchestrationClient (binding_string )
813+ client ._get_async_request = get_mock .get
814+
815+ with pytest .raises (Exception ) as ex :
816+ await client .restart (TEST_INSTANCE_ID )
817+ assert f"instanceId { TEST_INSTANCE_ID } was not found" in str (ex .value )
0 commit comments