Skip to content

Commit 65ad7da

Browse files
committed
Test: ChildWorkflow assertions
1 parent 97402e1 commit 65ad7da

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

tests/test_serialization_context.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ async def passthrough_activity(input: TraceData) -> TraceData:
5959
return input
6060

6161

62+
@workflow.defn(sandboxed=False)
63+
class EchoWorkflow:
64+
@workflow.run
65+
async def run(self, data: TraceData) -> TraceData:
66+
return data
67+
68+
6269
@workflow.defn(sandboxed=False) # we want to use isinstance
6370
class SerializationContextTestWorkflow:
6471
@workflow.run
@@ -69,6 +76,9 @@ async def run(self, data: TraceData) -> TraceData:
6976
start_to_close_timeout=timedelta(seconds=10),
7077
heartbeat_timeout=timedelta(seconds=2),
7178
)
79+
data = await workflow.execute_child_workflow(
80+
EchoWorkflow.run, data, id=f"{workflow.info().workflow_id}_child"
81+
)
7282
return data
7383

7484

@@ -179,7 +189,7 @@ async def test_workflow_payload_conversion_can_be_given_access_to_serialization_
179189
async with Worker(
180190
client,
181191
task_queue=task_queue,
182-
workflows=[SerializationContextTestWorkflow],
192+
workflows=[SerializationContextTestWorkflow, EchoWorkflow],
183193
activities=[passthrough_activity],
184194
):
185195
result = await client.execute_workflow(
@@ -195,6 +205,12 @@ async def test_workflow_payload_conversion_can_be_given_access_to_serialization_
195205
workflow_id=workflow_id,
196206
)
197207
)
208+
child_workflow_context = dataclasses.asdict(
209+
WorkflowSerializationContext(
210+
namespace="default",
211+
workflow_id=f"{workflow_id}_child",
212+
)
213+
)
198214
activity_context = dataclasses.asdict(
199215
ActivitySerializationContext(
200216
namespace="default",
@@ -251,6 +267,30 @@ async def test_workflow_payload_conversion_can_be_given_access_to_serialization_
251267
method="from_payload",
252268
context=activity_context, # Inbound activity result
253269
),
270+
TraceItem(
271+
context_type="workflow",
272+
in_workflow=True,
273+
method="to_payload",
274+
context=child_workflow_context, # Outbound child workflow input
275+
),
276+
TraceItem(
277+
context_type="workflow",
278+
in_workflow=False,
279+
method="from_payload",
280+
context=child_workflow_context, # Inbound child workflow input
281+
),
282+
TraceItem(
283+
context_type="workflow",
284+
in_workflow=True,
285+
method="to_payload",
286+
context=child_workflow_context, # Outbound child workflow result
287+
),
288+
TraceItem(
289+
context_type="workflow",
290+
in_workflow=False,
291+
method="from_payload",
292+
context=child_workflow_context, # Inbound child workflow result
293+
),
254294
TraceItem(
255295
context_type="workflow",
256296
in_workflow=True,

0 commit comments

Comments
 (0)