Skip to content

Commit e0c751e

Browse files
committed
Test workflow outbound nexus interception
1 parent 2affa25 commit e0c751e

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/worker/test_interceptor.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from temporalio import activity, workflow
77
from temporalio.client import Client, WorkflowUpdateFailedError
8-
from temporalio.exceptions import ApplicationError
8+
from temporalio.exceptions import ApplicationError, NexusOperationError
99
from temporalio.testing import WorkflowEnvironment
1010
from temporalio.worker import (
1111
ActivityInboundInterceptor,
@@ -27,6 +27,7 @@
2727
WorkflowInterceptorClassInput,
2828
WorkflowOutboundInterceptor,
2929
)
30+
from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name
3031

3132
# Passing through because Python 3.9 has an import bug at
3233
# https://github.com/python/cpython/issues/91351
@@ -169,6 +170,24 @@ async def run(self, style: str) -> None:
169170
)
170171
await child_handle
171172

173+
nexus_client = workflow.create_nexus_client(
174+
endpoint=make_nexus_endpoint_name(workflow.info().task_queue),
175+
service="non-existent-nexus-service",
176+
)
177+
try:
178+
await nexus_client.start_operation(
179+
operation="non-existent-nexus-operation",
180+
input={"test": "data"},
181+
schedule_to_close_timeout=timedelta(microseconds=1),
182+
)
183+
raise Exception("unreachable")
184+
except NexusOperationError:
185+
# The test requires only that the workflow attempts to schedule the nexus operation.
186+
# Instead of setting up a nexus service, we deliberately schedule a call to a
187+
# non-existent nexus operation with an insufficiently long timeout, and expect this
188+
# error.
189+
pass
190+
172191
await self.finish.wait()
173192
workflow.continue_as_new("continue-as-new")
174193

@@ -200,7 +219,9 @@ async def test_worker_interceptor(client: Client, env: WorkflowEnvironment):
200219
pytest.skip(
201220
"Java test server: https://github.com/temporalio/sdk-java/issues/1424"
202221
)
203-
task_queue = f"task_queue_{uuid.uuid4()}"
222+
task_queue = f"task-queue-{uuid.uuid4()}"
223+
await create_nexus_endpoint(task_queue, client)
224+
204225
async with Worker(
205226
client,
206227
task_queue=task_queue,
@@ -276,6 +297,8 @@ def pop_trace(name: str, filter: Optional[Callable[[Any], bool]] = None) -> Any:
276297
"workflow.signal_external_workflow",
277298
lambda v: v.args[0] == "external-signal-val",
278299
)
300+
assert pop_trace("workflow.info")
301+
assert pop_trace("workflow.start_nexus_operation")
279302
assert pop_trace(
280303
"workflow.signal", lambda v: v.args[0] == "external-signal-val"
281304
)

0 commit comments

Comments
 (0)