|
3 | 3 | Tests for Decision Events Iterator. |
4 | 4 | """ |
5 | 5 |
|
| 6 | +from typing import List |
6 | 7 | import pytest |
7 | 8 |
|
8 | 9 |
|
9 | 10 | from cadence._internal.workflow.decision_events_iterator import ( |
10 | 11 | DecisionEventsIterator, |
11 | 12 | ) |
12 | | -from tests.cadence._internal.workflow.utils import create_mock_history_event |
| 13 | +from cadence.api.v1.history_pb2 import HistoryEvent |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class TestDecisionEventsIterator: |
@@ -104,3 +105,61 @@ def test_successful_cases(self, name, event_types, expected): |
104 | 105 | assert batch.replay == expect["replay"] |
105 | 106 | assert batch.replay_current_time_milliseconds == expect["replay_time"] |
106 | 107 | assert batch.next_decision_event_id == expect["next_decision_event_id"] |
| 108 | + |
| 109 | + |
| 110 | +def create_mock_history_event(event_types: List[str]) -> List[HistoryEvent]: |
| 111 | + events = [] |
| 112 | + for i, event_type in enumerate(event_types): |
| 113 | + event = HistoryEvent() |
| 114 | + event.event_id = i + 1 |
| 115 | + event.event_time.FromMilliseconds((i + 1) * 1000) |
| 116 | + |
| 117 | + # Set the appropriate attribute based on event type |
| 118 | + if event_type == "decision_task_started": |
| 119 | + event.decision_task_started_event_attributes.SetInParent() |
| 120 | + elif event_type == "decision_task_completed": |
| 121 | + event.decision_task_completed_event_attributes.SetInParent() |
| 122 | + elif event_type == "decision_task_failed": |
| 123 | + event.decision_task_failed_event_attributes.SetInParent() |
| 124 | + elif event_type == "decision_task_timed_out": |
| 125 | + event.decision_task_timed_out_event_attributes.SetInParent() |
| 126 | + elif event_type == "marker_recorded": |
| 127 | + event.marker_recorded_event_attributes.SetInParent() |
| 128 | + elif event_type == "activity_scheduled": |
| 129 | + event.activity_task_scheduled_event_attributes.SetInParent() |
| 130 | + elif event_type == "activity_started": |
| 131 | + event.activity_task_started_event_attributes.SetInParent() |
| 132 | + elif event_type == "activity_completed": |
| 133 | + event.activity_task_completed_event_attributes.SetInParent() |
| 134 | + elif event_type == "activity_failed": |
| 135 | + event.activity_task_failed_event_attributes.SetInParent() |
| 136 | + elif event_type == "activity_timed_out": |
| 137 | + event.activity_task_timed_out_event_attributes.SetInParent() |
| 138 | + elif event_type == "activity_cancel_requested": |
| 139 | + event.activity_task_cancel_requested_event_attributes.SetInParent() |
| 140 | + elif event_type == "request_cancel_activity_task_failed": |
| 141 | + event.request_cancel_activity_task_failed_event_attributes.SetInParent() |
| 142 | + elif event_type == "activity_canceled": |
| 143 | + event.activity_task_canceled_event_attributes.SetInParent() |
| 144 | + elif event_type == "timer_started": |
| 145 | + event.timer_started_event_attributes.SetInParent() |
| 146 | + elif event_type == "timer_fired": |
| 147 | + event.timer_fired_event_attributes.SetInParent() |
| 148 | + elif event_type == "timer_canceled": |
| 149 | + event.timer_canceled_event_attributes.SetInParent() |
| 150 | + elif event_type == "cancel_timer_failed": |
| 151 | + event.cancel_timer_failed_event_attributes.SetInParent() |
| 152 | + elif event_type == "request_cancel_external_workflow_execution_initiated": |
| 153 | + event.request_cancel_external_workflow_execution_initiated_event_attributes.SetInParent() |
| 154 | + elif event_type == "request_cancel_external_workflow_execution_failed": |
| 155 | + event.request_cancel_external_workflow_execution_failed_event_attributes.SetInParent() |
| 156 | + elif event_type == "external_workflow_execution_cancel_requested": |
| 157 | + event.external_workflow_execution_cancel_requested_event_attributes.SetInParent() |
| 158 | + elif event_type == "workflow_execution_started": |
| 159 | + event.workflow_execution_started_event_attributes.SetInParent() |
| 160 | + elif event_type == "workflow_execution_completed": |
| 161 | + event.workflow_execution_completed_event_attributes.SetInParent() |
| 162 | + |
| 163 | + events.append(event) |
| 164 | + |
| 165 | + return events |
0 commit comments