|
19 | 19 | MESSAGE_500 = 'instance failed with unhandled exception'
|
20 | 20 | MESSAGE_501 = "well we didn't expect that"
|
21 | 21 |
|
| 22 | +INSTANCE_ID = "2e2568e7-a906-43bd-8364-c81733c5891e" |
| 23 | +REASON = "Stuff" |
| 24 | + |
22 | 25 | TEST_ORCHESTRATOR = "MyDurableOrchestrator"
|
23 | 26 | EXCEPTION_ORCHESTRATOR_NOT_FOUND_EXMESSAGE = "The function <orchestrator> doesn't exist,"\
|
24 | 27 | " is disabled, or is not an orchestrator function. Additional info: "\
|
@@ -540,3 +543,52 @@ async def test_start_new_orchestrator_internal_exception(binding_string):
|
540 | 543 | with pytest.raises(Exception) as ex:
|
541 | 544 | await client.start_new(TEST_ORCHESTRATOR)
|
542 | 545 | ex.match(status_str)
|
| 546 | + |
| 547 | +@pytest.mark.asyncio |
| 548 | +async def test_rewind_works_under_200_and_200_http_codes(binding_string): |
| 549 | + """Tests that the rewind API works as expected under 'successful' http codes: 200, 202""" |
| 550 | + client = DurableOrchestrationClient(binding_string) |
| 551 | + for code in [200, 202]: |
| 552 | + mock_request = MockRequest( |
| 553 | + expected_url=f"{RPC_BASE_URL}instances/{INSTANCE_ID}/rewind?reason={REASON}", |
| 554 | + response=[code, ""]) |
| 555 | + client._post_async_request = mock_request.post |
| 556 | + result = await client.rewind(INSTANCE_ID, REASON) |
| 557 | + assert result is None |
| 558 | + |
| 559 | +@pytest.mark.asyncio |
| 560 | +async def test_rewind_throws_exception_during_404_410_and_500_errors(binding_string): |
| 561 | + """Tests the behaviour of rewind under 'exception' http codes: 404, 410, 500""" |
| 562 | + client = DurableOrchestrationClient(binding_string) |
| 563 | + codes = [404, 410, 500] |
| 564 | + exception_strs = [ |
| 565 | + f"No instance with ID {INSTANCE_ID} found.", |
| 566 | + "The rewind operation is only supported on failed orchestration instances.", |
| 567 | + "Something went wrong" |
| 568 | + ] |
| 569 | + for http_code, expected_exception_str in zip(codes, exception_strs): |
| 570 | + mock_request = MockRequest( |
| 571 | + expected_url=f"{RPC_BASE_URL}instances/{INSTANCE_ID}/rewind?reason={REASON}", |
| 572 | + response=[http_code, "Something went wrong"]) |
| 573 | + client._post_async_request = mock_request.post |
| 574 | + |
| 575 | + with pytest.raises(Exception) as ex: |
| 576 | + await client.rewind(INSTANCE_ID, REASON) |
| 577 | + ex_message = str(ex.value) |
| 578 | + assert ex_message == expected_exception_str |
| 579 | + |
| 580 | +@pytest.mark.asyncio |
| 581 | +async def test_rewind_with_no_rpc_endpoint(binding_string): |
| 582 | + """Tests the behaviour of rewind without an RPC endpoint / under the legacy HTTP endpoint.""" |
| 583 | + client = DurableOrchestrationClient(binding_string) |
| 584 | + mock_request = MockRequest( |
| 585 | + expected_url=f"{RPC_BASE_URL}instances/{INSTANCE_ID}/rewind?reason={REASON}", |
| 586 | + response=[-1, ""]) |
| 587 | + client._post_async_request = mock_request.post |
| 588 | + client._orchestration_bindings._rpc_base_url = None |
| 589 | + expected_exception_str = "The Python SDK only supports RPC endpoints."\ |
| 590 | + + "Please remove the `localRpcEnabled` setting from host.json" |
| 591 | + with pytest.raises(Exception) as ex: |
| 592 | + await client.rewind(INSTANCE_ID, REASON) |
| 593 | + ex_message = str(ex.value) |
| 594 | + assert ex_message == expected_exception_str |
0 commit comments