Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ async def purge_instance_history(self, instance_id: str) -> PurgeHistoryResult:
The results of the request to delete the orchestration instance
"""
request_url = f"{self._orchestration_bindings.rpc_base_url}instances/{instance_id}"
response = await self._delete_async_request(request_url)
response = await self._delete_async_request(
request_url,
function_invocation_id=self._function_invocation_id)
return self._parse_purge_instance_history_response(response)

async def purge_instance_history_by(
Expand Down Expand Up @@ -448,7 +450,9 @@ async def purge_instance_history_by(
created_time_to=created_time_to,
runtime_status=runtime_status)
request_url = options.to_url(self._orchestration_bindings.rpc_base_url)
response = await self._delete_async_request(request_url)
response = await self._delete_async_request(
request_url,
function_invocation_id=self._function_invocation_id)
return self._parse_purge_instance_history_response(response)

async def terminate(self, instance_id: str, reason: str) -> None:
Expand Down
85 changes: 84 additions & 1 deletion tests/models/test_DurableOrchestrationClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def get(self, url: str):
assert url == self._expected_url
return self._response

async def delete(self, url: str):
async def delete(self, url: str, function_invocation_id: str = None):
assert url == self._expected_url
return self._response

Expand Down Expand Up @@ -861,6 +861,13 @@ async def post(self, url: str, data: Any = None, trace_parent: str = None,
assert function_invocation_id == self._expected_invocation_id
return self._response

async def delete(self, url: str, function_invocation_id: str = None):
assert url == self._expected_url
self._received_invocation_id = function_invocation_id
if self._expected_invocation_id is not None:
assert function_invocation_id == self._expected_invocation_id
return self._response


@pytest.mark.asyncio
async def test_start_new_passes_invocation_id(binding_string):
Expand Down Expand Up @@ -894,3 +901,79 @@ async def test_start_new_passes_none_when_no_invocation_id(binding_string):

await client.start_new(function_name)
assert mock_request.received_invocation_id is None


@pytest.mark.asyncio
async def test_purge_instance_history_passes_invocation_id(binding_string):
"""Test that purge_instance_history passes the function_invocation_id to the HTTP request."""
invocation_id = "test-invocation-456"

mock_request = MockRequestWithInvocationId(
expected_url=f"{RPC_BASE_URL}instances/{TEST_INSTANCE_ID}",
response=[200, dict(instancesDeleted=1)],
expected_invocation_id=invocation_id)

client = DurableOrchestrationClient(
binding_string, function_invocation_id=invocation_id)
client._delete_async_request = mock_request.delete

result = await client.purge_instance_history(TEST_INSTANCE_ID)
assert result.instances_deleted == 1
assert mock_request.received_invocation_id == invocation_id


@pytest.mark.asyncio
async def test_purge_instance_history_passes_none_when_no_invocation_id(binding_string):
"""Test that purge_instance_history passes None when no invocation ID is provided."""
mock_request = MockRequestWithInvocationId(
expected_url=f"{RPC_BASE_URL}instances/{TEST_INSTANCE_ID}",
response=[200, dict(instancesDeleted=1)])

client = DurableOrchestrationClient(binding_string)
client._delete_async_request = mock_request.delete

result = await client.purge_instance_history(TEST_INSTANCE_ID)
assert result.instances_deleted == 1
assert mock_request.received_invocation_id is None


@pytest.mark.asyncio
async def test_purge_instance_history_by_passes_invocation_id(binding_string):
"""Test that purge_instance_history_by passes invocation_id to the HTTP request."""
invocation_id = "test-invocation-456"

mock_request = MockRequestWithInvocationId(
expected_url=f"{RPC_BASE_URL}instances/"
"?createdTimeFrom=2000-01-01T00:00:00.000000Z"
"&runtimeStatus=Completed",
response=[200, dict(instancesDeleted=1)],
expected_invocation_id=invocation_id)

client = DurableOrchestrationClient(
binding_string, function_invocation_id=invocation_id)
client._delete_async_request = mock_request.delete

result = await client.purge_instance_history_by(
created_time_from=datetime(2000, 1, 1),
runtime_status=[OrchestrationRuntimeStatus.Completed])
assert result.instances_deleted == 1
assert mock_request.received_invocation_id == invocation_id


@pytest.mark.asyncio
async def test_purge_instance_history_by_passes_none_when_no_invocation_id(binding_string):
"""Test that purge_instance_history_by passes None when no invocation ID is given."""
mock_request = MockRequestWithInvocationId(
expected_url=f"{RPC_BASE_URL}instances/"
"?createdTimeFrom=2000-01-01T00:00:00.000000Z"
"&runtimeStatus=Completed",
response=[200, dict(instancesDeleted=1)])

client = DurableOrchestrationClient(binding_string)
client._delete_async_request = mock_request.delete

result = await client.purge_instance_history_by(
created_time_from=datetime(2000, 1, 1),
runtime_status=[OrchestrationRuntimeStatus.Completed])
assert result.instances_deleted == 1
assert mock_request.received_invocation_id is None