|
8 | 8 | StartWorkflowExecutionRequest, |
9 | 9 | StartWorkflowExecutionResponse, |
10 | 10 | ) |
11 | | -from cadence.client import Client, StartWorkflowOptions, _validate_and_apply_defaults |
| 11 | +from cadence.client import Client, StartWorkflowOptions, _validate_and_apply_defaults, _resolve_cron_overlap_policy |
| 12 | +from cadence.api.v1 import workflow_pb2 |
12 | 13 | from cadence.data_converter import DefaultDataConverter |
13 | 14 | from cadence.workflow import WorkflowDefinition, WorkflowDefinitionOptions |
14 | 15 |
|
@@ -241,6 +242,103 @@ async def test_build_request_with_cron_schedule(self, mock_client): |
241 | 242 |
|
242 | 243 | assert request.cron_schedule == "0 * * * *" |
243 | 244 |
|
| 245 | + @pytest.mark.asyncio |
| 246 | + async def test_build_request_with_cron_overlap_policy_enum(self, mock_client): |
| 247 | + """Test building request with cron_overlap_policy as enum.""" |
| 248 | + client = Client(domain="test-domain", target="localhost:7933") |
| 249 | + |
| 250 | + options = StartWorkflowOptions( |
| 251 | + task_list="test-task-list", |
| 252 | + execution_start_to_close_timeout=timedelta(minutes=10), |
| 253 | + task_start_to_close_timeout=timedelta(seconds=30), |
| 254 | + cron_schedule="0 * * * *", |
| 255 | + cron_overlap_policy=workflow_pb2.CRON_OVERLAP_POLICY_SKIPPED, |
| 256 | + ) |
| 257 | + |
| 258 | + request = client._build_start_workflow_request("TestWorkflow", (), options) |
| 259 | + |
| 260 | + assert request.cron_overlap_policy == workflow_pb2.CRON_OVERLAP_POLICY_SKIPPED |
| 261 | + |
| 262 | + @pytest.mark.asyncio |
| 263 | + async def test_build_request_with_cron_overlap_policy_string_skipped(self, mock_client): |
| 264 | + """Test building request with cron_overlap_policy as string 'SKIPPED'.""" |
| 265 | + client = Client(domain="test-domain", target="localhost:7933") |
| 266 | + |
| 267 | + options = StartWorkflowOptions( |
| 268 | + task_list="test-task-list", |
| 269 | + execution_start_to_close_timeout=timedelta(minutes=10), |
| 270 | + task_start_to_close_timeout=timedelta(seconds=30), |
| 271 | + cron_schedule="0 * * * *", |
| 272 | + cron_overlap_policy="SKIPPED", |
| 273 | + ) |
| 274 | + |
| 275 | + request = client._build_start_workflow_request("TestWorkflow", (), options) |
| 276 | + |
| 277 | + assert request.cron_overlap_policy == workflow_pb2.CRON_OVERLAP_POLICY_SKIPPED |
| 278 | + |
| 279 | + @pytest.mark.asyncio |
| 280 | + async def test_build_request_with_cron_overlap_policy_string_buffer_one(self, mock_client): |
| 281 | + """Test building request with cron_overlap_policy as string 'BUFFER_ONE'.""" |
| 282 | + client = Client(domain="test-domain", target="localhost:7933") |
| 283 | + |
| 284 | + options = StartWorkflowOptions( |
| 285 | + task_list="test-task-list", |
| 286 | + execution_start_to_close_timeout=timedelta(minutes=10), |
| 287 | + task_start_to_close_timeout=timedelta(seconds=30), |
| 288 | + cron_schedule="0 * * * *", |
| 289 | + cron_overlap_policy="BUFFER_ONE", |
| 290 | + ) |
| 291 | + |
| 292 | + request = client._build_start_workflow_request("TestWorkflow", (), options) |
| 293 | + |
| 294 | + assert request.cron_overlap_policy == workflow_pb2.CRON_OVERLAP_POLICY_BUFFER_ONE |
| 295 | + |
| 296 | + @pytest.mark.asyncio |
| 297 | + async def test_build_request_with_cron_overlap_policy_string_lowercase(self, mock_client): |
| 298 | + """Test building request with cron_overlap_policy as lowercase string.""" |
| 299 | + client = Client(domain="test-domain", target="localhost:7933") |
| 300 | + |
| 301 | + options = StartWorkflowOptions( |
| 302 | + task_list="test-task-list", |
| 303 | + execution_start_to_close_timeout=timedelta(minutes=10), |
| 304 | + task_start_to_close_timeout=timedelta(seconds=30), |
| 305 | + cron_schedule="0 * * * *", |
| 306 | + cron_overlap_policy="skipped", |
| 307 | + ) |
| 308 | + |
| 309 | + request = client._build_start_workflow_request("TestWorkflow", (), options) |
| 310 | + |
| 311 | + assert request.cron_overlap_policy == workflow_pb2.CRON_OVERLAP_POLICY_SKIPPED |
| 312 | + |
| 313 | + |
| 314 | +class TestResolveCronOverlapPolicy: |
| 315 | + """Test _resolve_cron_overlap_policy helper function.""" |
| 316 | + |
| 317 | + def test_resolve_enum_value(self): |
| 318 | + """Test resolving protobuf enum value.""" |
| 319 | + result = _resolve_cron_overlap_policy(workflow_pb2.CRON_OVERLAP_POLICY_SKIPPED) |
| 320 | + assert result == workflow_pb2.CRON_OVERLAP_POLICY_SKIPPED |
| 321 | + |
| 322 | + def test_resolve_string_skipped(self): |
| 323 | + """Test resolving string 'SKIPPED'.""" |
| 324 | + result = _resolve_cron_overlap_policy("SKIPPED") |
| 325 | + assert result == workflow_pb2.CRON_OVERLAP_POLICY_SKIPPED |
| 326 | + |
| 327 | + def test_resolve_string_buffer_one(self): |
| 328 | + """Test resolving string 'BUFFER_ONE'.""" |
| 329 | + result = _resolve_cron_overlap_policy("BUFFER_ONE") |
| 330 | + assert result == workflow_pb2.CRON_OVERLAP_POLICY_BUFFER_ONE |
| 331 | + |
| 332 | + def test_resolve_string_lowercase(self): |
| 333 | + """Test resolving lowercase string.""" |
| 334 | + result = _resolve_cron_overlap_policy("buffer_one") |
| 335 | + assert result == workflow_pb2.CRON_OVERLAP_POLICY_BUFFER_ONE |
| 336 | + |
| 337 | + def test_resolve_invalid_string_raises_error(self): |
| 338 | + """Test that invalid string raises ValueError.""" |
| 339 | + with pytest.raises(ValueError, match="Invalid cron_overlap_policy"): |
| 340 | + _resolve_cron_overlap_policy("INVALID_POLICY") |
| 341 | + |
244 | 342 |
|
245 | 343 | class TestClientStartWorkflow: |
246 | 344 | """Test Client.start_workflow method.""" |
|
0 commit comments