Skip to content

Commit c1756c6

Browse files
committed
Extend logging tests to cover no-info branch with bug
1 parent 052abb7 commit c1756c6

File tree

1 file changed

+55
-22
lines changed

1 file changed

+55
-22
lines changed

tests/worker/test_workflow.py

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,8 +1948,29 @@ def find_log(self, starts_with: str) -> Optional[logging.LogRecord]:
19481948
return None
19491949

19501950

1951-
async def test_workflow_logging(client: Client, env: WorkflowEnvironment):
1952-
workflow.logger.full_workflow_info_on_extra = True
1951+
@pytest.mark.parametrize(
1952+
"with_workflow_info",
1953+
[True, False],
1954+
)
1955+
async def test_workflow_logging(
1956+
client: Client, env: WorkflowEnvironment, with_workflow_info: bool
1957+
):
1958+
orig_on_message = workflow.logger.workflow_info_on_message
1959+
orig_on_extra = workflow.logger.workflow_info_on_extra
1960+
orig_full_on_extra = workflow.logger.full_workflow_info_on_extra
1961+
1962+
try:
1963+
workflow.logger.workflow_info_on_message = with_workflow_info
1964+
workflow.logger.workflow_info_on_extra = with_workflow_info
1965+
workflow.logger.full_workflow_info_on_extra = with_workflow_info
1966+
await _do_workflow_logging_test(client, with_workflow_info)
1967+
finally:
1968+
workflow.logger.workflow_info_on_message = orig_on_message
1969+
workflow.logger.workflow_info_on_extra = orig_on_extra
1970+
workflow.logger.full_workflow_info_on_extra = orig_full_on_extra
1971+
1972+
1973+
async def _do_workflow_logging_test(client: Client, with_workflow_info: bool):
19531974
with LogCapturer().logs_captured(
19541975
workflow.logger.base_logger, activity.logger.base_logger
19551976
) as capturer:
@@ -1976,30 +1997,42 @@ async def test_workflow_logging(client: Client, env: WorkflowEnvironment):
19761997
assert "signal 2" == await handle.query(LoggingWorkflow.last_signal)
19771998

19781999
# Confirm logs were produced
1979-
assert capturer.find_log("Signal: signal 1 ({'attempt':")
2000+
assert capturer.find_log("Signal: signal 1")
19802001
assert capturer.find_log("Signal: signal 2")
19812002
assert capturer.find_log("Update: update 1")
19822003
assert capturer.find_log("Update: update 2")
19832004
assert not capturer.find_log("Signal: signal 3")
1984-
# Also make sure it has some workflow info and correct funcName
1985-
record = capturer.find_log("Signal: signal 1")
1986-
assert (
1987-
record
1988-
and record.__dict__["temporal_workflow"]["workflow_type"]
1989-
== "LoggingWorkflow"
1990-
and record.funcName == "my_signal"
1991-
)
1992-
# Since we enabled full info, make sure it's there
1993-
assert isinstance(record.__dict__["workflow_info"], workflow.Info)
1994-
# Check the log emitted by the update execution.
1995-
record = capturer.find_log("Update: update 1")
1996-
assert (
1997-
record
1998-
and record.__dict__["temporal_workflow"]["update_id"] == "update-1"
1999-
and record.__dict__["temporal_workflow"]["update_name"] == "my_update"
2000-
and "'update_id': 'update-1'" in record.message
2001-
and "'update_name': 'my_update'" in record.message
2002-
)
2005+
2006+
if with_workflow_info:
2007+
record = capturer.find_log("Signal: signal 1 ({'attempt':")
2008+
assert (
2009+
record
2010+
and record.__dict__["temporal_workflow"]["workflow_type"]
2011+
== "LoggingWorkflow"
2012+
and record.funcName == "my_signal"
2013+
)
2014+
# Since we enabled full info, make sure it's there
2015+
assert isinstance(record.__dict__["workflow_info"], workflow.Info)
2016+
2017+
# Check the log emitted by the update execution.
2018+
record = capturer.find_log("Update: update 1")
2019+
assert (
2020+
record
2021+
and record.__dict__["temporal_workflow"]["update_id"] == "update-1"
2022+
and record.__dict__["temporal_workflow"]["update_name"] == "my_update"
2023+
and "'update_id': 'update-1'" in record.message
2024+
and "'update_name': 'my_update'" in record.message
2025+
)
2026+
else:
2027+
record = capturer.find_log("Signal: signal 1")
2028+
assert record and "temporal_workflow" not in record.__dict__
2029+
assert record and "workflow_info" not in record.__dict__
2030+
2031+
record = capturer.find_log("Update: update 1")
2032+
assert record and "temporal_workflow" not in record.__dict__
2033+
assert record and "workflow_info" not in record.__dict__
2034+
assert "'update_id': 'update-1'" not in record.message
2035+
assert "'update_name': 'my_update'" not in record.message
20032036

20042037
# Clear queue and start a new one with more signals
20052038
capturer.log_queue.queue.clear()

0 commit comments

Comments
 (0)