Skip to content

Commit 4d7b99d

Browse files
committed
fix unit test
Signed-off-by: Shijie Sheng <[email protected]>
1 parent f7c7f21 commit 4d7b99d

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

tests/cadence/_internal/workflow/test_workflow_engine_integration.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,22 @@ def mock_client(self):
3131
return client
3232

3333
@pytest.fixture
34-
def workflow_info(self):
34+
def workflow_info(self, mock_client, decision_task):
3535
"""Create workflow info."""
36-
data_converter = Mock()
37-
data_converter.from_data = Mock(return_value=["test-input"])
3836
return WorkflowInfo(
3937
workflow_type="test_workflow",
4038
workflow_domain="test-domain",
4139
workflow_id="test-workflow-id",
4240
workflow_run_id="test-run-id",
4341
workflow_task_list="test-task-list",
44-
workflow_events = [],
45-
data_converter=data_converter,
42+
workflow_events=decision_task.history.events,
43+
data_converter=mock_client.data_converter,
4644
)
4745

46+
@pytest.fixture
47+
def decision_task(self):
48+
return self.create_mock_decision_task()
49+
4850
@pytest.fixture
4951
def mock_workflow_definition(self):
5052
"""Create a mock workflow definition."""
@@ -105,9 +107,10 @@ def create_mock_decision_task(
105107
return decision_task
106108

107109
@pytest.mark.asyncio
108-
async def test_process_decision_success(self, workflow_engine, mock_client):
110+
async def test_process_decision_success(
111+
self, workflow_engine, mock_client, decision_task
112+
):
109113
"""Test successful decision processing."""
110-
decision_task = self.create_mock_decision_task()
111114

112115
# Mock the decision manager to return some decisions
113116
with patch.object(
@@ -123,9 +126,10 @@ async def test_process_decision_success(self, workflow_engine, mock_client):
123126
assert len(result.decisions) == 1
124127

125128
@pytest.mark.asyncio
126-
async def test_process_decision_with_history(self, workflow_engine, mock_client):
129+
async def test_process_decision_with_history(
130+
self, workflow_engine, mock_client, decision_task
131+
):
127132
"""Test decision processing with history events."""
128-
decision_task = self.create_mock_decision_task()
129133

130134
# Mock the decision manager
131135
with patch.object(
@@ -144,14 +148,12 @@ async def test_process_decision_with_history(self, workflow_engine, mock_client)
144148

145149
@pytest.mark.asyncio
146150
async def test_process_decision_workflow_complete(
147-
self, workflow_engine, mock_client
151+
self, workflow_engine, mock_client, decision_task
148152
):
149153
"""Test decision processing when workflow is already complete."""
150154
# Mark workflow as complete
151155
workflow_engine._is_workflow_complete = True
152156

153-
decision_task = self.create_mock_decision_task()
154-
155157
with patch.object(
156158
workflow_engine._decision_manager,
157159
"collect_pending_decisions",
@@ -165,9 +167,10 @@ async def test_process_decision_workflow_complete(
165167
assert len(result.decisions) == 0
166168

167169
@pytest.mark.asyncio
168-
async def test_process_decision_error_handling(self, workflow_engine, mock_client):
170+
async def test_process_decision_error_handling(
171+
self, workflow_engine, mock_client, decision_task
172+
):
169173
"""Test decision processing error handling."""
170-
decision_task = self.create_mock_decision_task()
171174

172175
# Mock the decision manager to raise an exception
173176
with patch.object(
@@ -183,9 +186,10 @@ async def test_process_decision_error_handling(self, workflow_engine, mock_clien
183186
assert len(result.decisions) == 0
184187

185188
@pytest.mark.asyncio
186-
async def test_extract_workflow_input_success(self, workflow_engine, mock_client):
189+
async def test_extract_workflow_input_success(
190+
self, workflow_engine: "WorkflowEngine", mock_client, decision_task
191+
):
187192
"""Test successful workflow input extraction."""
188-
decision_task = self.create_mock_decision_task()
189193

190194
# Extract workflow input
191195
input_data = workflow_engine._extract_workflow_input(decision_task)
@@ -241,10 +245,9 @@ async def test_extract_workflow_input_no_started_event(
241245

242246
@pytest.mark.asyncio
243247
async def test_extract_workflow_input_deserialization_error(
244-
self, workflow_engine, mock_client
248+
self, workflow_engine, mock_client, decision_task
245249
):
246250
"""Test workflow input extraction with deserialization error."""
247-
decision_task = self.create_mock_decision_task()
248251

249252
# Mock data converter to raise an exception
250253
mock_client.data_converter.from_data = AsyncMock(
@@ -313,15 +316,14 @@ def test_workflow_engine_initialization(
313316

314317
@pytest.mark.asyncio
315318
async def test_workflow_engine_without_workflow_definition(
316-
self, mock_client, workflow_info
319+
self, mock_client: Client, workflow_info, decision_task
317320
):
318321
"""Test WorkflowEngine without workflow definition."""
319322
engine = WorkflowEngine(
320-
info=workflow_info, client=mock_client, workflow_definition=None
323+
info=workflow_info,
324+
workflow_definition=None,
321325
)
322326

323-
decision_task = self.create_mock_decision_task()
324-
325327
with patch.object(
326328
engine._decision_manager, "collect_pending_decisions", return_value=[]
327329
):
@@ -334,10 +336,9 @@ async def test_workflow_engine_without_workflow_definition(
334336

335337
@pytest.mark.asyncio
336338
async def test_workflow_engine_workflow_completion(
337-
self, workflow_engine, mock_client
339+
self, workflow_engine, mock_client, decision_task
338340
):
339341
"""Test workflow completion detection."""
340-
decision_task = self.create_mock_decision_task()
341342

342343
# Create a workflow definition that returns a result (indicating completion)
343344
class CompletingWorkflow:
@@ -372,10 +373,9 @@ def test_close_event_loop(self, workflow_engine):
372373

373374
@pytest.mark.asyncio
374375
async def test_process_decision_with_query_results(
375-
self, workflow_engine, mock_client
376+
self, workflow_engine, mock_client, decision_task
376377
):
377378
"""Test decision processing with query results."""
378-
decision_task = self.create_mock_decision_task()
379379

380380
# Mock the decision manager to return decisions with query results
381381
mock_decisions = [Mock()]

0 commit comments

Comments
 (0)