-
Notifications
You must be signed in to change notification settings - Fork 32
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
Open
andystaples
wants to merge
3
commits into
main
Choose a base branch
from
andystaples-add-purge-timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # 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 | ||
|
berndverst marked this conversation as resolved.
|
||
|
|
||
|
|
||
| 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") | ||
|
|
||
|
|
||
| @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()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.