-
Notifications
You must be signed in to change notification settings - Fork 144
Test workflow outbound nexus interception #1064
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
|
|
||
| from temporalio import activity, workflow | ||
| from temporalio.client import Client, WorkflowUpdateFailedError | ||
| from temporalio.exceptions import ApplicationError | ||
| from temporalio.exceptions import ApplicationError, NexusOperationError | ||
| from temporalio.testing import WorkflowEnvironment | ||
| from temporalio.worker import ( | ||
| ActivityInboundInterceptor, | ||
|
|
@@ -27,6 +27,8 @@ | |
| WorkflowInterceptorClassInput, | ||
| WorkflowOutboundInterceptor, | ||
| ) | ||
| from temporalio.worker._interceptor import StartNexusOperationInput | ||
| from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name | ||
|
|
||
| # Passing through because Python 3.9 has an import bug at | ||
| # https://github.com/python/cpython/issues/91351 | ||
|
|
@@ -127,6 +129,12 @@ def start_local_activity( | |
| interceptor_traces.append(("workflow.start_local_activity", input)) | ||
| return super().start_local_activity(input) | ||
|
|
||
| async def start_nexus_operation( | ||
| self, input: StartNexusOperationInput | ||
| ) -> workflow.NexusOperationHandle: | ||
| interceptor_traces.append(("workflow.start_nexus_operation", input)) | ||
| return await super().start_nexus_operation(input) | ||
|
|
||
|
|
||
| @activity.defn | ||
| async def intercepted_activity(param: str) -> str: | ||
|
|
@@ -169,6 +177,24 @@ async def run(self, style: str) -> None: | |
| ) | ||
| await child_handle | ||
|
|
||
| nexus_client = workflow.create_nexus_client( | ||
| endpoint=make_nexus_endpoint_name(workflow.info().task_queue), | ||
| service="non-existent-nexus-service", | ||
| ) | ||
| try: | ||
| await nexus_client.start_operation( | ||
| operation="non-existent-nexus-operation", | ||
| input={"test": "data"}, | ||
| schedule_to_close_timeout=timedelta(microseconds=1), | ||
| ) | ||
| raise Exception("unreachable") | ||
| except NexusOperationError: | ||
| # The test requires only that the workflow attempts to schedule the nexus operation. | ||
| # Instead of setting up a nexus service, we deliberately schedule a call to a | ||
| # non-existent nexus operation with an insufficiently long timeout, and expect this | ||
| # error. | ||
| pass | ||
|
|
||
| await self.finish.wait() | ||
| workflow.continue_as_new("continue-as-new") | ||
|
|
||
|
|
@@ -200,7 +226,9 @@ async def test_worker_interceptor(client: Client, env: WorkflowEnvironment): | |
| pytest.skip( | ||
| "Java test server: https://github.com/temporalio/sdk-java/issues/1424" | ||
| ) | ||
| task_queue = f"task_queue_{uuid.uuid4()}" | ||
| task_queue = f"task-queue-{uuid.uuid4()}" | ||
| await create_nexus_endpoint(task_queue, client) | ||
|
|
||
| async with Worker( | ||
| client, | ||
| task_queue=task_queue, | ||
|
|
@@ -276,6 +304,8 @@ def pop_trace(name: str, filter: Optional[Callable[[Any], bool]] = None) -> Any: | |
| "workflow.signal_external_workflow", | ||
| lambda v: v.args[0] == "external-signal-val", | ||
| ) | ||
| assert pop_trace("workflow.info") | ||
| assert pop_trace("workflow.start_nexus_operation") | ||
|
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. Bug: Trace Assertion Order MismatchThe test's trace assertions for |
||
| assert pop_trace( | ||
| "workflow.signal", lambda v: v.args[0] == "external-signal-val" | ||
| ) | ||
|
|
||
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.
Bug: Interceptor Missing Method, Duplicate Trace Assertion
The test has two assertion failures related to interceptor traces:
TracingWorkflowOutboundInterceptorlacks astart_nexus_operationmethod, preventing interception ofnexus_client.start_operationand causing thepop_trace("workflow.start_nexus_operation")assertion to fail.pop_trace("workflow.info")assertion exists. The first call consumes the trace, leading to the second assertion's failure.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 was a valid finding; I'd acidentally lost some of the commit in a git rebasing operation.