Skip to content

Commit b29d6eb

Browse files
committed
Test update
1 parent 7be554c commit b29d6eb

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tests/test_serialization_context.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,88 @@ async def test_query_payload_conversion(
480480
)
481481

482482

483+
# Update test
484+
485+
486+
@workflow.defn
487+
class UpdateSerializationContextTestWorkflow:
488+
@workflow.run
489+
async def run(self) -> None:
490+
await asyncio.Event().wait()
491+
492+
@workflow.update
493+
def my_update(self, input: TraceData) -> TraceData:
494+
return input
495+
496+
497+
async def test_update_payload_conversion(
498+
client: Client,
499+
):
500+
workflow_id = str(uuid.uuid4())
501+
task_queue = str(uuid.uuid4())
502+
503+
data_converter = dataclasses.replace(
504+
DataConverter.default,
505+
payload_converter_class=SerializationContextTestPayloadConverter,
506+
)
507+
508+
config = client.config()
509+
config["data_converter"] = data_converter
510+
custom_client = Client(**config)
511+
512+
async with Worker(
513+
custom_client,
514+
task_queue=task_queue,
515+
workflows=[UpdateSerializationContextTestWorkflow],
516+
activities=[],
517+
workflow_runner=UnsandboxedWorkflowRunner(), # so that we can use isinstance
518+
):
519+
handle = await custom_client.start_workflow(
520+
UpdateSerializationContextTestWorkflow.run,
521+
id=workflow_id,
522+
task_queue=task_queue,
523+
)
524+
result = await handle.execute_update(
525+
UpdateSerializationContextTestWorkflow.my_update, TraceData()
526+
)
527+
528+
workflow_context = dataclasses.asdict(
529+
WorkflowSerializationContext(
530+
namespace="default",
531+
workflow_id=workflow_id,
532+
)
533+
)
534+
assert_trace(
535+
result.items,
536+
[
537+
TraceItem(
538+
context_type="workflow",
539+
in_workflow=False,
540+
method="to_payload",
541+
context=workflow_context, # Outbound update input
542+
),
543+
TraceItem(
544+
context_type="workflow",
545+
in_workflow=True,
546+
method="from_payload",
547+
context=workflow_context, # Inbound update input
548+
),
549+
TraceItem(
550+
context_type="workflow",
551+
in_workflow=True,
552+
method="to_payload",
553+
context=workflow_context, # Outbound update result
554+
),
555+
TraceItem(
556+
context_type="workflow",
557+
in_workflow=False,
558+
method="from_payload",
559+
context=workflow_context, # Inbound update result
560+
),
561+
],
562+
)
563+
564+
483565
# Utilities
484566

485567

0 commit comments

Comments
 (0)