|
13 | 13 | ActivityWorkItemFilter, |
14 | 14 | EntityWorkItemFilter, |
15 | 15 | OrchestrationWorkItemFilter, |
| 16 | + VersioningOptions, |
| 17 | + VersionMatchStrategy, |
16 | 18 | WorkItemFilters, |
17 | 19 | ) |
18 | 20 | from durabletask.azuremanaged.client import DurableTaskSchedulerClient |
@@ -262,3 +264,139 @@ def ping(self, _): |
262 | 264 |
|
263 | 265 | assert matched_invoked |
264 | 266 | assert not unmatched_invoked |
| 267 | + |
| 268 | + |
| 269 | +# ------------------------------------------------------------------ |
| 270 | +# Tests: version-aware filtering with strict versioning |
| 271 | +# ------------------------------------------------------------------ |
| 272 | + |
| 273 | +def _simple_v2_orchestrator(ctx: task.OrchestrationContext, input: int): |
| 274 | + """Orchestrator that returns immediately (no activities) for version tests.""" |
| 275 | + return input + 1 |
| 276 | + |
| 277 | + |
| 278 | +def test_strict_version_matching_orchestration_completes(): |
| 279 | + """Orchestration scheduled with the matching version is processed.""" |
| 280 | + with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True, |
| 281 | + taskhub=taskhub_name, token_credential=None) as w: |
| 282 | + w.add_orchestrator(_simple_v2_orchestrator) |
| 283 | + w.use_versioning(VersioningOptions( |
| 284 | + version="2.0", |
| 285 | + match_strategy=VersionMatchStrategy.STRICT, |
| 286 | + )) |
| 287 | + w.use_work_item_filters() # auto-generate with version |
| 288 | + w.start() |
| 289 | + |
| 290 | + c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True, |
| 291 | + taskhub=taskhub_name, token_credential=None) |
| 292 | + id = c.schedule_new_orchestration( |
| 293 | + _simple_v2_orchestrator, input=10, version="2.0") |
| 294 | + state = c.wait_for_orchestration_completion(id, timeout=30) |
| 295 | + |
| 296 | + assert state is not None |
| 297 | + assert state.runtime_status == client.OrchestrationStatus.COMPLETED |
| 298 | + assert state.serialized_output == "11" |
| 299 | + |
| 300 | + |
| 301 | +def test_strict_version_incompatible_orchestration_stays_pending(): |
| 302 | + """Orchestration with an incompatible version is not dispatched and stays pending.""" |
| 303 | + with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True, |
| 304 | + taskhub=taskhub_name, token_credential=None) as w: |
| 305 | + w.add_orchestrator(_simple_v2_orchestrator) |
| 306 | + w.use_versioning(VersioningOptions( |
| 307 | + version="2.0", |
| 308 | + match_strategy=VersionMatchStrategy.STRICT, |
| 309 | + )) |
| 310 | + w.use_work_item_filters() |
| 311 | + w.start() |
| 312 | + |
| 313 | + c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True, |
| 314 | + taskhub=taskhub_name, token_credential=None) |
| 315 | + |
| 316 | + # Schedule with version "1.0" — incompatible with the worker's "2.0" |
| 317 | + bad_id = c.schedule_new_orchestration( |
| 318 | + _simple_v2_orchestrator, input=5, version="1.0") |
| 319 | + |
| 320 | + # Schedule a compatible one so we can confirm the worker is active |
| 321 | + good_id = c.schedule_new_orchestration( |
| 322 | + _simple_v2_orchestrator, input=5, version="2.0") |
| 323 | + good_state = c.wait_for_orchestration_completion(good_id, timeout=30) |
| 324 | + |
| 325 | + assert good_state is not None |
| 326 | + assert good_state.runtime_status == client.OrchestrationStatus.COMPLETED |
| 327 | + |
| 328 | + # The incompatible orchestration must remain pending (not failed) |
| 329 | + bad_state = c.get_orchestration_state(bad_id) |
| 330 | + assert bad_state is not None |
| 331 | + assert bad_state.runtime_status == client.OrchestrationStatus.PENDING |
| 332 | + |
| 333 | + |
| 334 | +def test_strict_version_no_version_orchestration_stays_pending(): |
| 335 | + """Orchestration scheduled without a version is not dispatched by a strict worker.""" |
| 336 | + with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True, |
| 337 | + taskhub=taskhub_name, token_credential=None) as w: |
| 338 | + w.add_orchestrator(_simple_v2_orchestrator) |
| 339 | + w.use_versioning(VersioningOptions( |
| 340 | + version="2.0", |
| 341 | + match_strategy=VersionMatchStrategy.STRICT, |
| 342 | + )) |
| 343 | + w.use_work_item_filters() |
| 344 | + w.start() |
| 345 | + |
| 346 | + c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True, |
| 347 | + taskhub=taskhub_name, token_credential=None) |
| 348 | + |
| 349 | + # Schedule without any version |
| 350 | + no_ver_id = c.schedule_new_orchestration( |
| 351 | + _simple_v2_orchestrator, input=1) |
| 352 | + |
| 353 | + # Schedule a compatible one to prove the worker is running |
| 354 | + good_id = c.schedule_new_orchestration( |
| 355 | + _simple_v2_orchestrator, input=1, version="2.0") |
| 356 | + good_state = c.wait_for_orchestration_completion(good_id, timeout=30) |
| 357 | + assert good_state is not None |
| 358 | + assert good_state.runtime_status == client.OrchestrationStatus.COMPLETED |
| 359 | + |
| 360 | + # The unversioned orchestration must remain pending |
| 361 | + no_ver_state = c.get_orchestration_state(no_ver_id) |
| 362 | + assert no_ver_state is not None |
| 363 | + assert no_ver_state.runtime_status == client.OrchestrationStatus.PENDING |
| 364 | + |
| 365 | + |
| 366 | +def test_strict_version_explicit_filters_with_versions(): |
| 367 | + """Explicit filters with version constraints enforce strict matching.""" |
| 368 | + custom_filters = WorkItemFilters( |
| 369 | + orchestrations=[ |
| 370 | + OrchestrationWorkItemFilter( |
| 371 | + name=task.get_name(_simple_v2_orchestrator), |
| 372 | + versions=["3.0"], |
| 373 | + ), |
| 374 | + ], |
| 375 | + ) |
| 376 | + |
| 377 | + with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True, |
| 378 | + taskhub=taskhub_name, token_credential=None) as w: |
| 379 | + w.add_orchestrator(_simple_v2_orchestrator) |
| 380 | + w.use_work_item_filters(custom_filters) |
| 381 | + w.start() |
| 382 | + |
| 383 | + c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True, |
| 384 | + taskhub=taskhub_name, token_credential=None) |
| 385 | + |
| 386 | + # Version "2.0" does not match the filter's "3.0" |
| 387 | + bad_id = c.schedule_new_orchestration( |
| 388 | + _simple_v2_orchestrator, input=1, version="2.0") |
| 389 | + |
| 390 | + # Version "3.0" should match |
| 391 | + good_id = c.schedule_new_orchestration( |
| 392 | + _simple_v2_orchestrator, input=1, version="3.0") |
| 393 | + good_state = c.wait_for_orchestration_completion(good_id, timeout=30) |
| 394 | + |
| 395 | + assert good_state is not None |
| 396 | + assert good_state.runtime_status == client.OrchestrationStatus.COMPLETED |
| 397 | + assert good_state.serialized_output == "2" |
| 398 | + |
| 399 | + # Mismatched version must remain pending |
| 400 | + bad_state = c.get_orchestration_state(bad_id) |
| 401 | + assert bad_state is not None |
| 402 | + assert bad_state.runtime_status == client.OrchestrationStatus.PENDING |
0 commit comments