Skip to content

Commit f5803cd

Browse files
committed
Fix test to access links in both places on workflow event
1 parent 0479201 commit f5803cd

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tests/nexus/test_workflow_caller.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
from nexusrpc.handler._decorators import operation_handler
2424

2525
import temporalio.api
26+
import temporalio.api.common.v1
2627
import temporalio.api.enums.v1
28+
import temporalio.api.history.v1
2729
import temporalio.nexus._operation_handlers
2830
from temporalio import nexus, workflow
2931
from temporalio.client import (
@@ -1113,11 +1115,12 @@ async def assert_handler_workflow_has_link_to_caller_workflow(
11131115
== temporalio.api.enums.v1.EventType.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
11141116
)
11151117
)
1116-
if not len(wf_started_event.links) == 1:
1118+
links = _get_links_from_workflow_execution_started_event(wf_started_event)
1119+
if not len(links) == 1:
11171120
pytest.fail(
1118-
f"Expected 1 link on WorkflowExecutionStarted event, got {len(wf_started_event.links)}"
1121+
f"Expected 1 link on WorkflowExecutionStarted event, got {len(links)}"
11191122
)
1120-
[link] = wf_started_event.links
1123+
[link] = links
11211124
assert link.workflow_event.namespace == caller_wf_handle._client.namespace
11221125
assert link.workflow_event.workflow_id == caller_wf_handle.id
11231126
assert link.workflow_event.run_id
@@ -1128,6 +1131,17 @@ async def assert_handler_workflow_has_link_to_caller_workflow(
11281131
)
11291132

11301133

1134+
def _get_links_from_workflow_execution_started_event(
1135+
event: temporalio.api.history.v1.HistoryEvent,
1136+
) -> list[temporalio.api.common.v1.Link]:
1137+
[callback] = event.workflow_execution_started_event_attributes.completion_callbacks
1138+
if links := callback.links:
1139+
assert not event.links, "Did not expect both callback.links and event.links"
1140+
return list(links)
1141+
else:
1142+
return list(event.links)
1143+
1144+
11311145
# When request_cancel is True, the NexusOperationHandle in the workflow evolves
11321146
# through the following states:
11331147
# start_fut result_fut handle_task w/ fut_waiter (task._must_cancel)

0 commit comments

Comments
 (0)