Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 31
Add timeout support for filtered orchestration purge#255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| from datetime import timedelta | ||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
| import pytest | ||
| from google.protobuf import wrappers_pb2 | ||
| import durabletask.internal.orchestrator_service_pb2 as pb | ||
| from durabletask.client import AsyncTaskHubGrpcClient, TaskHubGrpcClient | ||
| def test_sync_filtered_purge_serializes_timeout(): | ||
| stub = MagicMock() | ||
| stub.PurgeInstances.return_value = pb.PurgeInstancesResponse( | ||
| deletedInstanceCount=1, | ||
| isComplete=wrappers_pb2.BoolValue(value=False), | ||
| ) | ||
| with ( | ||
| patch("durabletask.client.shared.get_grpc_channel", return_value=MagicMock()), | ||
| patch("durabletask.client.stubs.TaskHubSidecarServiceStub", return_value=stub), | ||
| ): | ||
| client = TaskHubGrpcClient() | ||
| result = client.purge_orchestrations_by(timeout=timedelta(seconds=1, microseconds=500000)) | ||
| request = stub.PurgeInstances.call_args.args[0] | ||
| assert request.purgeInstanceFilter.timeout.seconds == 1 | ||
| assert request.purgeInstanceFilter.timeout.nanos == 500000000 | ||
| assert result.is_complete is False | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in aa8942c. PurgeInstancesResult.is_complete is now bool | None and preserves isComplete field presence; added coverage for an omitted completion field. | ||
| def test_sync_filtered_purge_omits_timeout_when_not_supplied(): | ||
| stub = MagicMock() | ||
| stub.PurgeInstances.return_value = pb.PurgeInstancesResponse( | ||
| isComplete=wrappers_pb2.BoolValue(value=True), | ||
| ) | ||
| with ( | ||
| patch("durabletask.client.shared.get_grpc_channel", return_value=MagicMock()), | ||
| patch("durabletask.client.stubs.TaskHubSidecarServiceStub", return_value=stub), | ||
| ): | ||
| client = TaskHubGrpcClient() | ||
| client.purge_orchestrations_by() | ||
| request = stub.PurgeInstances.call_args.args[0] | ||
| assert not request.purgeInstanceFilter.HasField("timeout") | ||
| def test_sync_filtered_purge_preserves_unknown_completion_state(): | ||
| stub = MagicMock() | ||
| stub.PurgeInstances.return_value = pb.PurgeInstancesResponse() | ||
| with ( | ||
| patch("durabletask.client.shared.get_grpc_channel", return_value=MagicMock()), | ||
| patch("durabletask.client.stubs.TaskHubSidecarServiceStub", return_value=stub), | ||
| ): | ||
| client = TaskHubGrpcClient() | ||
| result = client.purge_orchestrations_by() | ||
| assert result.is_complete is None | ||
| @pytest.mark.parametrize("timeout", [timedelta(), timedelta(seconds=-1)]) | ||
| def test_sync_filtered_purge_rejects_non_positive_timeout(timeout): | ||
| client = TaskHubGrpcClient(channel=MagicMock()) | ||
| with pytest.raises(ValueError, match="timeout must be greater than zero"): | ||
| client.purge_orchestrations_by(timeout=timeout) | ||
| @pytest.mark.asyncio | ||
| async def test_async_filtered_purge_serializes_timeout(): | ||
| stub = MagicMock() | ||
| stub.PurgeInstances = AsyncMock(return_value=pb.PurgeInstancesResponse( | ||
| deletedInstanceCount=1, | ||
| isComplete=wrappers_pb2.BoolValue(value=False), | ||
| )) | ||
| channel = MagicMock() | ||
| channel.close = AsyncMock() | ||
| with ( | ||
| patch("durabletask.client.shared.get_async_grpc_channel", return_value=channel), | ||
| patch("durabletask.client.stubs.TaskHubSidecarServiceStub", return_value=stub), | ||
| ): | ||
| client = AsyncTaskHubGrpcClient() | ||
| result = await client.purge_orchestrations_by(timeout=timedelta(milliseconds=250)) | ||
| await client.close() | ||
| request = stub.PurgeInstances.call_args.args[0] | ||
| assert request.purgeInstanceFilter.timeout.seconds == 0 | ||
| assert request.purgeInstanceFilter.timeout.nanos == 250000000 | ||
| assert result.is_complete is False | ||
| @pytest.mark.asyncio | ||
| async def test_async_filtered_purge_rejects_non_positive_timeout(): | ||
| client = AsyncTaskHubGrpcClient(channel=MagicMock()) | ||
| with pytest.raises(ValueError, match="timeout must be greater than zero"): | ||
| await client.purge_orchestrations_by(timeout=timedelta()) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DurableTaskSchedulerClient,AsyncDurableTaskSchedulerClient,DurableFunctionsClient, andSyncDurableFunctionsClientall inherit this API. The repository changelog policy requires every affected package to document user-facing changes, and the rewind precedent did so. Please add## Unreleasedentries todurabletask-azuremanaged/CHANGELOG.mdandazure-functions-durable/CHANGELOG.md.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in aa8942c. Added Unreleased entries to both durabletask-azuremanaged and azure-functions-durable changelogs for the inherited filtered-purge timeout API.