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