Skip to content

Commit f94249e

Browse files
committed
Test
1 parent f452f03 commit f94249e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tests/worker/test_workflow.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,10 @@ def my_signal(self, value: str) -> None:
19081908
self._last_signal = value
19091909
workflow.logger.info(f"Signal: {value}")
19101910

1911+
@workflow.update
1912+
def my_update(self, value: str) -> None:
1913+
workflow.logger.info(f"Update: {value}")
1914+
19111915
@workflow.query
19121916
def last_signal(self) -> str:
19131917
return self._last_signal
@@ -1955,14 +1959,22 @@ async def test_workflow_logging(client: Client, env: WorkflowEnvironment):
19551959
id=f"workflow-{uuid.uuid4()}",
19561960
task_queue=worker.task_queue,
19571961
)
1958-
# Send a couple signals
1962+
# Send some signals and updates
19591963
await handle.signal(LoggingWorkflow.my_signal, "signal 1")
19601964
await handle.signal(LoggingWorkflow.my_signal, "signal 2")
1965+
await handle.execute_update(
1966+
LoggingWorkflow.my_update, "update 1", id="update-1"
1967+
)
1968+
await handle.execute_update(
1969+
LoggingWorkflow.my_update, "update 2", id="update-2"
1970+
)
19611971
assert "signal 2" == await handle.query(LoggingWorkflow.last_signal)
19621972

1963-
# Confirm two logs happened
1973+
# Confirm logs were produced
19641974
assert capturer.find_log("Signal: signal 1 ({'attempt':")
19651975
assert capturer.find_log("Signal: signal 2")
1976+
assert capturer.find_log("Update: update 1")
1977+
assert capturer.find_log("Update: update 2")
19661978
assert not capturer.find_log("Signal: signal 3")
19671979
# Also make sure it has some workflow info and correct funcName
19681980
record = capturer.find_log("Signal: signal 1")
@@ -1974,6 +1986,15 @@ async def test_workflow_logging(client: Client, env: WorkflowEnvironment):
19741986
)
19751987
# Since we enabled full info, make sure it's there
19761988
assert isinstance(record.__dict__["workflow_info"], workflow.Info)
1989+
# Check the log emitted by the update execution.
1990+
record = capturer.find_log("Update: update 1")
1991+
assert (
1992+
record
1993+
and record.__dict__["temporal_update"]["id"] == "update-1"
1994+
and record.__dict__["temporal_update"]["name"] == "my_update"
1995+
and "'update_id': 'update-1'" in record.message
1996+
and "'update_name': 'my_update'" in record.message
1997+
)
19771998

19781999
# Clear queue and start a new one with more signals
19792000
capturer.log_queue.queue.clear()
@@ -1983,7 +2004,7 @@ async def test_workflow_logging(client: Client, env: WorkflowEnvironment):
19832004
task_queue=worker.task_queue,
19842005
max_cached_workflows=0,
19852006
) as worker:
1986-
# Send a couple signals
2007+
# Send signals and updates
19872008
await handle.signal(LoggingWorkflow.my_signal, "signal 3")
19882009
await handle.signal(LoggingWorkflow.my_signal, "finish")
19892010
await handle.result()

0 commit comments

Comments
 (0)