|
112 | 112 | from tests.helpers import (
|
113 | 113 | admitted_update_task,
|
114 | 114 | assert_eq_eventually,
|
| 115 | + assert_workflow_exists_eventually, |
115 | 116 | ensure_search_attributes_present,
|
116 | 117 | find_free_port,
|
117 | 118 | new_worker,
|
@@ -1126,26 +1127,9 @@ async def test_workflow_cancel_child_started(client: Client, use_execute: bool):
|
1126 | 1127 | task_queue=worker.task_queue,
|
1127 | 1128 | )
|
1128 | 1129 |
|
1129 |
| - # Wait until child started |
1130 |
| - async def child_started() -> bool: |
1131 |
| - try: |
1132 |
| - return await handle.query( |
1133 |
| - CancelChildWorkflow.ready |
1134 |
| - ) and await client.get_workflow_handle_for( |
1135 |
| - LongSleepWorkflow.run, # type: ignore[arg-type] |
1136 |
| - workflow_id=f"{handle.id}_child", |
1137 |
| - ).query(LongSleepWorkflow.started) |
1138 |
| - except RPCError as err: |
1139 |
| - # Ignore not-found or failed precondition because child may |
1140 |
| - # not have started yet |
1141 |
| - if ( |
1142 |
| - err.status == RPCStatusCode.NOT_FOUND |
1143 |
| - or err.status == RPCStatusCode.FAILED_PRECONDITION |
1144 |
| - ): |
1145 |
| - return False |
1146 |
| - raise |
1147 |
| - |
1148 |
| - await assert_eq_eventually(True, child_started) |
| 1130 | + await assert_workflow_exists_eventually( |
| 1131 | + client, LongSleepWorkflow.run, f"{handle.id}_child" |
| 1132 | + ) |
1149 | 1133 | # Send cancel signal and wait on the handle
|
1150 | 1134 | await handle.signal(CancelChildWorkflow.cancel_child)
|
1151 | 1135 | with pytest.raises(WorkflowFailureError) as err:
|
@@ -7081,3 +7065,65 @@ async def test_workflow_priorities(client: Client, env: WorkflowEnvironment):
|
7081 | 7065 | task_queue=worker.task_queue,
|
7082 | 7066 | )
|
7083 | 7067 | await handle.result()
|
| 7068 | + |
| 7069 | + |
| 7070 | +@workflow.defn |
| 7071 | +class ExposeRootChildWorkflow: |
| 7072 | + def __init__(self) -> None: |
| 7073 | + self.blocked = True |
| 7074 | + |
| 7075 | + @workflow.signal |
| 7076 | + def unblock(self) -> None: |
| 7077 | + self.blocked = False |
| 7078 | + |
| 7079 | + @workflow.run |
| 7080 | + async def run(self) -> Optional[temporalio.workflow.RootInfo]: |
| 7081 | + await workflow.wait_condition(lambda: not self.blocked) |
| 7082 | + return workflow.info().root |
| 7083 | + |
| 7084 | + |
| 7085 | +@workflow.defn |
| 7086 | +class ExposeRootWorkflow: |
| 7087 | + @workflow.run |
| 7088 | + async def run(self, child_wf_id) -> Optional[temporalio.workflow.RootInfo]: |
| 7089 | + return await workflow.execute_child_workflow( |
| 7090 | + ExposeRootChildWorkflow.run, id=child_wf_id |
| 7091 | + ) |
| 7092 | + |
| 7093 | + |
| 7094 | +async def test_expose_root_execution(client: Client, env: WorkflowEnvironment): |
| 7095 | + if env.supports_time_skipping: |
| 7096 | + pytest.skip( |
| 7097 | + "Java test server needs release with: https://github.com/temporalio/sdk-java/pull/2441" |
| 7098 | + ) |
| 7099 | + async with new_worker( |
| 7100 | + client, ExposeRootWorkflow, ExposeRootChildWorkflow |
| 7101 | + ) as worker: |
| 7102 | + parent_wf_id = f"workflow-{uuid.uuid4()}" |
| 7103 | + child_wf_id = parent_wf_id + "_child" |
| 7104 | + handle = await client.start_workflow( |
| 7105 | + ExposeRootWorkflow.run, |
| 7106 | + child_wf_id, |
| 7107 | + id=parent_wf_id, |
| 7108 | + task_queue=worker.task_queue, |
| 7109 | + ) |
| 7110 | + |
| 7111 | + await assert_workflow_exists_eventually( |
| 7112 | + client, ExposeRootChildWorkflow, child_wf_id |
| 7113 | + ) |
| 7114 | + child_handle: WorkflowHandle = client.get_workflow_handle_for( |
| 7115 | + ExposeRootChildWorkflow.run, child_wf_id |
| 7116 | + ) |
| 7117 | + child_desc = await child_handle.describe() |
| 7118 | + parent_desc = await handle.describe() |
| 7119 | + # Assert child root execution is the same as it's parent execution |
| 7120 | + assert child_desc.root_id == parent_desc.id |
| 7121 | + assert child_desc.root_run_id == parent_desc.run_id |
| 7122 | + # Unblock child |
| 7123 | + await child_handle.signal(ExposeRootChildWorkflow.unblock) |
| 7124 | + # Get the result (child info) |
| 7125 | + child_wf_info_root = await handle.result() |
| 7126 | + # Assert root execution in child info is same as it's parent execution |
| 7127 | + assert child_wf_info_root is not None |
| 7128 | + assert child_wf_info_root.workflow_id == parent_desc.id |
| 7129 | + assert child_wf_info_root.run_id == parent_desc.run_id |
0 commit comments