From 918ab3d52af908dc18aad8bcc49f824ca84523f6 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Thu, 18 Jan 2024 08:28:57 -0500 Subject: [PATCH] Clean up --- features/signal/basic/feature.py | 11 ++--- features/signal/child_workflow/feature.py | 10 ++-- features/update/basic/feature.py | 59 ----------------------- features/update/basic_async/feature.py | 21 +++----- 4 files changed, 15 insertions(+), 86 deletions(-) diff --git a/features/signal/basic/feature.py b/features/signal/basic/feature.py index a7e831b9..8cfc69ec 100644 --- a/features/signal/basic/feature.py +++ b/features/signal/basic/feature.py @@ -5,18 +5,15 @@ from harness.python.feature import Runner, register_feature -WORKFLOW_INITIAL_STATE = "1" -SIGNAL_ARG = "2" - @workflow.defn class Workflow: def __init__(self) -> None: - self._state = WORKFLOW_INITIAL_STATE + self._state = "" @workflow.run async def run(self) -> str: - await workflow.wait_condition(lambda: self._state != WORKFLOW_INITIAL_STATE) + await workflow.wait_condition(lambda: self._state != "") return self._state @workflow.signal @@ -31,12 +28,12 @@ async def start(runner: Runner) -> WorkflowHandle: task_queue=runner.task_queue, execution_timeout=timedelta(minutes=1), ) - await handle.signal(Workflow.my_signal, SIGNAL_ARG) + await handle.signal(Workflow.my_signal, "arg") return handle register_feature( workflows=[Workflow], - expect_run_result=SIGNAL_ARG, + expect_run_result="arg", start=start, ) diff --git a/features/signal/child_workflow/feature.py b/features/signal/child_workflow/feature.py index 26549ee8..3e68da2c 100644 --- a/features/signal/child_workflow/feature.py +++ b/features/signal/child_workflow/feature.py @@ -7,18 +7,14 @@ from harness.python.feature import Runner, register_feature -CHILD_WORKFLOW_INPUT = "child-input" -SIGNAL_ARG = "signal-arg" - - @workflow.defn class Workflow: @workflow.run async def run(self) -> str: child_wf = await workflow.start_child_workflow( - ChildWorkflow.run, CHILD_WORKFLOW_INPUT + ChildWorkflow.run, "child-wf-arg" ) - await child_wf.signal(ChildWorkflow.my_signal, SIGNAL_ARG) + await child_wf.signal(ChildWorkflow.my_signal, "signal-arg") return await child_wf @@ -43,6 +39,6 @@ async def start(runner: Runner) -> WorkflowHandle: register_feature( workflows=[Workflow, ChildWorkflow], - expect_run_result=f"{CHILD_WORKFLOW_INPUT} {SIGNAL_ARG}", + expect_run_result=f"child-wf-arg signal-arg", start=start, ) diff --git a/features/update/basic/feature.py b/features/update/basic/feature.py index 0d816cef..8a2f2650 100644 --- a/features/update/basic/feature.py +++ b/features/update/basic/feature.py @@ -1,4 +1,3 @@ -<<<<<<< HEAD import asyncio from datetime import timedelta @@ -38,61 +37,3 @@ async def check_result(runner: Runner, handle: WorkflowHandle) -> None: check_result=check_result, start=start, ) -||||||| parent of ea93e98 (Update features) -======= -from datetime import timedelta - -from temporalio import workflow -from temporalio.client import WorkflowHandle, WorkflowUpdateFailedError - -from harness.python.feature import Runner, register_feature - -WORKFLOW_INITIAL_STATE = "" -UPDATE_ARG = "update-arg" -BAD_UPDATE_ARG = "reject-me" -UPDATE_RESULT = "update-result" - - -@workflow.defn(name="Workflow") -class Workflow: - """ - A workflow with a signal and signal validator. - If accepted, the signal makes a change to workflow state. - The workflow does not terminate until such a change occurs. - """ - - def __init__(self) -> None: - self._state = WORKFLOW_INITIAL_STATE - - @workflow.run - async def run(self) -> str: - await workflow.wait_condition(lambda: self._state != WORKFLOW_INITIAL_STATE) - return self._state - - @workflow.update - async def my_update(self, arg: str) -> str: - self._state = arg - return UPDATE_RESULT - - @my_update.validator - def my_validate(self, arg: str): - if arg == BAD_UPDATE_ARG: - raise ValueError("Invalid Update argument") - - -async def checker(_: Runner, handle: WorkflowHandle): - try: - await handle.execute_update(Workflow.my_update, BAD_UPDATE_ARG) - except WorkflowUpdateFailedError: - pass - else: - assert False, "Expected Update to be rejected due to validation failure" - - update_result = await handle.execute_update(Workflow.my_update, UPDATE_ARG) - assert update_result == UPDATE_RESULT - result = await handle.result() - assert result == UPDATE_ARG - - -register_feature(workflows=[Workflow], check_result=checker) ->>>>>>> ea93e98 (Update features) diff --git a/features/update/basic_async/feature.py b/features/update/basic_async/feature.py index 0b3fc78b..bd1bba5c 100644 --- a/features/update/basic_async/feature.py +++ b/features/update/basic_async/feature.py @@ -5,11 +5,6 @@ from harness.python.feature import Runner, register_feature -WORKFLOW_INITIAL_STATE = "" -UPDATE_ARG = "update-arg" -BAD_UPDATE_ARG = "reject-me" -UPDATE_RESULT = "update-result" - @workflow.defn class Workflow: @@ -20,26 +15,26 @@ class Workflow: """ def __init__(self) -> None: - self._state = WORKFLOW_INITIAL_STATE + self._state = "" @workflow.run async def run(self) -> str: - await workflow.wait_condition(lambda: self._state != WORKFLOW_INITIAL_STATE) + await workflow.wait_condition(lambda: self._state != "") return self._state @workflow.update async def my_update(self, arg: str) -> str: self._state = arg - return UPDATE_RESULT + return "update-result" @my_update.validator def my_validate(self, arg: str): - if arg == BAD_UPDATE_ARG: + if arg == "bad-update-arg": raise ValueError("Invalid Update argument") async def checker(_: Runner, handle: WorkflowHandle): - bad_update_handle = await handle.start_update(Workflow.my_update, BAD_UPDATE_ARG) + bad_update_handle = await handle.start_update(Workflow.my_update, "bad-update-arg") try: await bad_update_handle.result() except WorkflowUpdateFailedError: @@ -47,11 +42,11 @@ async def checker(_: Runner, handle: WorkflowHandle): else: assert False, "Expected Update to be rejected due to validation failure" - update_handle = await handle.start_update(Workflow.my_update, UPDATE_ARG) + update_handle = await handle.start_update(Workflow.my_update, "update-arg") update_result = await update_handle.result() - assert update_result == UPDATE_RESULT + assert update_result == "update-result" result = await handle.result() - assert result == UPDATE_ARG + assert result == "update-arg" register_feature(workflows=[Workflow], check_result=checker)