-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Remove WorkflowEngine Caching and add basic Activity/Workflow integration tests #55
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
Merged
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -1,11 +1,32 @@ | ||
| import asyncio | ||
| from contextlib import asynccontextmanager | ||
| from typing import AsyncGenerator | ||
|
|
||
| from cadence import Registry | ||
| from cadence.client import ClientOptions, Client | ||
| from cadence.worker import WorkerOptions, Worker | ||
|
|
||
| DOMAIN_NAME = "test-domain" | ||
|
|
||
|
|
||
| class CadenceHelper: | ||
| def __init__(self, options: ClientOptions): | ||
| def __init__(self, options: ClientOptions, test_name: str) -> None: | ||
| self.options = options | ||
| self.test_name = test_name | ||
|
|
||
| @asynccontextmanager | ||
| async def worker( | ||
| self, registry: Registry, **kwargs: WorkerOptions | ||
| ) -> AsyncGenerator[Worker, None]: | ||
| async with self.client() as client: | ||
| worker = Worker(client, self.test_name, registry, **kwargs) | ||
| task = asyncio.create_task(worker.run()) | ||
| yield worker | ||
| task.cancel() | ||
| try: | ||
| await task | ||
| except asyncio.CancelledError: | ||
| pass | ||
|
|
||
| def client(self): | ||
| return Client(**self.options) |
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,146 @@ | ||
| import asyncio | ||
| from datetime import timedelta | ||
|
|
||
|
|
||
| from cadence import workflow, Registry | ||
| from cadence.api.v1.history_pb2 import EventFilterType | ||
| from cadence.api.v1.service_workflow_pb2 import ( | ||
| GetWorkflowExecutionHistoryRequest, | ||
| GetWorkflowExecutionHistoryResponse, | ||
| ) | ||
| from tests.integration_tests.helper import CadenceHelper, DOMAIN_NAME | ||
|
|
||
| reg = Registry() | ||
|
|
||
|
|
||
| @reg.activity() | ||
| async def echo(message: str) -> str: | ||
| return message | ||
|
|
||
|
|
||
| @reg.workflow() | ||
| class SingleActivity: | ||
| @workflow.run | ||
| async def run(self, message: str) -> str: | ||
| return await echo.with_options( | ||
| schedule_to_close_timeout=timedelta(seconds=10) | ||
| ).execute(message) | ||
|
|
||
|
|
||
| @reg.workflow() | ||
| class MultipleActivities: | ||
| @workflow.run | ||
| async def run(self, message: str) -> str: | ||
| await echo.with_options( | ||
| schedule_to_close_timeout=timedelta(seconds=10) | ||
| ).execute("first") | ||
|
|
||
| second = await echo.with_options( | ||
| schedule_to_close_timeout=timedelta(seconds=10) | ||
| ).execute(message) | ||
|
|
||
| await echo.with_options( | ||
| schedule_to_close_timeout=timedelta(seconds=10) | ||
| ).execute("third") | ||
|
|
||
| return second | ||
|
|
||
|
|
||
| @reg.workflow() | ||
| class ParallelActivities: | ||
| @workflow.run | ||
| async def run(self, message: str) -> str: | ||
| first = echo.with_options( | ||
| schedule_to_close_timeout=timedelta(seconds=10) | ||
| ).execute("first") | ||
|
|
||
| second = echo.with_options( | ||
| schedule_to_close_timeout=timedelta(seconds=10) | ||
| ).execute(message) | ||
|
|
||
| first_res, second_res = await asyncio.gather( | ||
| first, second, return_exceptions=True | ||
| ) | ||
|
|
||
| return second_res | ||
|
|
||
|
|
||
| async def test_single_activity(helper: CadenceHelper): | ||
| async with helper.worker(reg) as worker: | ||
| execution = await worker.client.start_workflow( | ||
| "SingleActivity", | ||
| "hello world", | ||
| task_list=worker.task_list, | ||
| execution_start_to_close_timeout=timedelta(seconds=10), | ||
| ) | ||
|
|
||
| response: GetWorkflowExecutionHistoryResponse = await worker.client.workflow_stub.GetWorkflowExecutionHistory( | ||
| GetWorkflowExecutionHistoryRequest( | ||
| domain=DOMAIN_NAME, | ||
| workflow_execution=execution, | ||
| wait_for_new_event=True, | ||
| history_event_filter_type=EventFilterType.EVENT_FILTER_TYPE_CLOSE_EVENT, | ||
| skip_archival=True, | ||
| ) | ||
| ) | ||
|
|
||
| assert ( | ||
| '"hello world"' | ||
| == response.history.events[ | ||
| -1 | ||
| ].workflow_execution_completed_event_attributes.result.data.decode() | ||
| ) | ||
|
|
||
|
|
||
| async def test_multiple_activities(helper: CadenceHelper): | ||
| async with helper.worker(reg) as worker: | ||
| execution = await worker.client.start_workflow( | ||
| "MultipleActivities", | ||
| "hello world", | ||
| task_list=worker.task_list, | ||
| execution_start_to_close_timeout=timedelta(seconds=10), | ||
| ) | ||
|
|
||
| response: GetWorkflowExecutionHistoryResponse = await worker.client.workflow_stub.GetWorkflowExecutionHistory( | ||
| GetWorkflowExecutionHistoryRequest( | ||
| domain=DOMAIN_NAME, | ||
| workflow_execution=execution, | ||
| wait_for_new_event=True, | ||
| history_event_filter_type=EventFilterType.EVENT_FILTER_TYPE_CLOSE_EVENT, | ||
| skip_archival=True, | ||
| ) | ||
| ) | ||
|
|
||
| assert ( | ||
| '"hello world"' | ||
| == response.history.events[ | ||
| -1 | ||
| ].workflow_execution_completed_event_attributes.result.data.decode() | ||
| ) | ||
|
|
||
|
|
||
| async def test_parallel_activities(helper: CadenceHelper): | ||
| async with helper.worker(reg) as worker: | ||
| execution = await worker.client.start_workflow( | ||
| "ParallelActivities", | ||
| "hello world", | ||
| task_list=worker.task_list, | ||
| execution_start_to_close_timeout=timedelta(seconds=10), | ||
| ) | ||
|
|
||
| response: GetWorkflowExecutionHistoryResponse = await worker.client.workflow_stub.GetWorkflowExecutionHistory( | ||
| GetWorkflowExecutionHistoryRequest( | ||
| domain=DOMAIN_NAME, | ||
| workflow_execution=execution, | ||
| wait_for_new_event=True, | ||
| history_event_filter_type=EventFilterType.EVENT_FILTER_TYPE_CLOSE_EVENT, | ||
| skip_archival=True, | ||
| ) | ||
| ) | ||
|
|
||
| assert ( | ||
| '"hello world"' | ||
| == response.history.events[ | ||
| -1 | ||
| ].workflow_execution_completed_event_attributes.result.data.decode() | ||
| ) |
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.
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.
This actually indicates a real data leak issue. But we can fix it later
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.
Discussed offline. There isn't a good solution to proactively delete the tasks. Cancelling tasks will trigger the workflow coroutine logic and may have unwanted side effects.
These tasks are weak references but will be deleted by GC eventually. So we'll just keep suppressing logging for now since it's expected behavior