Skip to content

Commit 23825e1

Browse files
committed
Replay test wf for temporalio/sdk-python#569
1 parent f3f9d89 commit 23825e1

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

dan/update_completion_after_main.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import asyncio
2+
import uuid
3+
4+
from temporalio import workflow
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
from utils import workflow_update_exists
8+
9+
wid = __file__
10+
tq = "tq"
11+
12+
13+
@workflow.defn
14+
class UpdateCompletionAfterWorkflowReturn:
15+
def __init__(self) -> None:
16+
self.workflow_returned = False
17+
18+
@workflow.run
19+
async def run(self) -> str:
20+
self.workflow_returned = True
21+
return "workflow-result"
22+
23+
@workflow.update
24+
async def my_update(self) -> str:
25+
await workflow.wait_condition(lambda: self.workflow_returned)
26+
return "update-result"
27+
28+
29+
async def main():
30+
client = await Client.connect("localhost:7233")
31+
32+
update_id = "my-update"
33+
task_queue = "tq"
34+
wf_handle = await client.start_workflow(
35+
UpdateCompletionAfterWorkflowReturn.run,
36+
id=f"wf-{uuid.uuid4()}",
37+
task_queue=task_queue,
38+
)
39+
update_result_task = asyncio.create_task(
40+
wf_handle.execute_update(
41+
UpdateCompletionAfterWorkflowReturn.my_update,
42+
id=update_id,
43+
)
44+
)
45+
await workflow_update_exists(client, wf_handle.id, update_id)
46+
47+
async with Worker(
48+
client,
49+
task_queue=task_queue,
50+
workflows=[UpdateCompletionAfterWorkflowReturn],
51+
):
52+
assert await wf_handle.result() == "workflow-result"
53+
assert await update_result_task == "update-result"
54+
55+
56+
if __name__ == "__main__":
57+
asyncio.run(main())

0 commit comments

Comments
 (0)