more examples of concurrent foreach
This commit is contained in:
@@ -13,6 +13,7 @@ from examples.authoring_concurrent_foreach import (
|
||||
record_item,
|
||||
run_async_ordered_example,
|
||||
run_collected_errors_example,
|
||||
run_replace_conflict_example,
|
||||
)
|
||||
from wf_authoring import WorkflowBuilder, state_path
|
||||
from wf_core import ForeachConcurrentPolicy
|
||||
@@ -74,6 +75,10 @@ def test_authoring_foreach_accepts_concurrent_policy_object() -> None:
|
||||
assert foreach.model_dump(mode="json")["concurrent"]["max_outstanding"] == 3
|
||||
|
||||
|
||||
def test_authoring_concurrent_foreach_example_documents_replace_conflict() -> None:
|
||||
run_replace_conflict_example()
|
||||
|
||||
|
||||
def test_authoring_foreach_deprecated_on_item_error_warns() -> None:
|
||||
builder = WorkflowBuilder(
|
||||
name="deprecated_item_error",
|
||||
|
||||
@@ -6,6 +6,10 @@ from examples.raw_canonical_workflow import (
|
||||
build_raw_canonical_workflow,
|
||||
run_raw_canonical_example,
|
||||
)
|
||||
from examples.raw_concurrent_foreach import (
|
||||
build_raw_concurrent_foreach_workflow,
|
||||
run_raw_concurrent_foreach_example,
|
||||
)
|
||||
|
||||
|
||||
def test_raw_canonical_workflow_runs() -> None:
|
||||
@@ -36,3 +40,31 @@ def test_raw_canonical_workflow_serializes_new_shape() -> None:
|
||||
assert node["output"][0]["target"] == {"root": "state", "parts": ["message"]}
|
||||
assert message_schema["type"] == "string"
|
||||
assert message_schema["reducer"] == "wf.std.replace"
|
||||
|
||||
|
||||
def test_raw_concurrent_foreach_workflow_runs() -> None:
|
||||
run = run_raw_concurrent_foreach_example()
|
||||
|
||||
assert run.status == RunStatus.COMPLETED
|
||||
assert run.output["seen"] == ["a", "c"]
|
||||
assert len(run.output["errors"]) == 1
|
||||
error = run.output["errors"][0]
|
||||
assert error["index"] == 1
|
||||
assert error["node_id"] == "record"
|
||||
assert error["error_type"] == "ValueError"
|
||||
assert error["message"] == "bad item"
|
||||
|
||||
|
||||
def test_raw_concurrent_foreach_serializes_canonical_policy_shape() -> None:
|
||||
workflow = build_raw_concurrent_foreach_workflow()
|
||||
dumped = workflow.model_dump(mode="json")
|
||||
foreach = dumped["nodes"][0]
|
||||
|
||||
assert foreach["mode"] == "concurrent"
|
||||
assert foreach["concurrent"]["max_active"] == 2
|
||||
assert foreach["item_error"]["action"] == "collect"
|
||||
assert foreach["item_error"]["collect_to"] == {
|
||||
"root": "state",
|
||||
"parts": ["errors"],
|
||||
}
|
||||
assert "on_item_error" not in foreach
|
||||
|
||||
Reference in New Issue
Block a user