From f9cb835e8a6cbd8e52297415c2e4c3c203093f6d Mon Sep 17 00:00:00 2001 From: Qian Li Date: Wed, 22 Jan 2025 17:31:59 -0800 Subject: [PATCH] Add test for the warning --- tests/test_queue.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_queue.py b/tests/test_queue.py index c45196f..1583600 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -1,3 +1,4 @@ +import logging import os import subprocess import threading @@ -478,7 +479,7 @@ def test_worker_concurrency_with_n_dbos_instances(dbos: DBOS) -> None: # Test error cases where we have duplicated workflows starting with the same workflow ID. -def test_duplicate_workflow_id(dbos: DBOS) -> None: +def test_duplicate_workflow_id(dbos: DBOS, caplog: pytest.LogCaptureFixture) -> None: wfid = str(uuid.uuid4()) @DBOS.workflow() @@ -510,11 +511,17 @@ def test_workflow(self, var1: str) -> str: DBOS.sleep(0.1) return self.config_name + ":" + var1 + original_propagate = logging.getLogger("dbos").propagate + caplog.set_level(logging.WARNING, "dbos") + logging.getLogger("dbos").propagate = True + with SetWorkflowID(wfid): origHandle = DBOS.start_workflow(test_workflow, "abc") # The second one will generate a warning message but no error. test_dup_workflow() + assert "Multiple workflow started within the SetWorkflowID block." in caplog.text + # It's okay to call the same workflow with the same ID again. with SetWorkflowID(wfid): same_handle = DBOS.start_workflow(test_workflow, "abc") @@ -559,6 +566,7 @@ def test_workflow(self, var1: str) -> str: with SetWorkflowID(wfid): handle = queue.enqueue(test_workflow, "abc") assert handle.get_result() == "abc" + assert "Workflow already exists in queue" in caplog.text # Call with a different input would generate a warning, but still use the recorded input. with SetWorkflowID(wfid): @@ -566,6 +574,10 @@ def test_workflow(self, var1: str) -> str: # We want to see the warning message, but the result is non-deterministic # TODO: in the future, we may want to always use the recorded inputs. assert res == "abc" or res == "def" + assert f"Workflow inputs for {wfid} changed since the first call" in caplog.text assert origHandle.get_result() == "abc" assert same_handle.get_result() == "abc" + + # Reset logging + logging.getLogger("dbos").propagate = original_propagate