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