diff --git a/tests/test_pipeline/test_job_run_summary.py b/tests/test_pipeline/test_job_run_summary.py index 645273cf7..9bbbb418d 100644 --- a/tests/test_pipeline/test_job_run_summary.py +++ b/tests/test_pipeline/test_job_run_summary.py @@ -29,7 +29,18 @@ ) from orcapod.pipeline.observer import NoOpObserver from orcapod.protocols.core_protocols import DataProtocol, TagProtocol -from orcapod.sources import DictSource +from orcapod.sources import ArrowTableSource, DictSource +from tests.test_core.operators.several_items import ( + DATA_FIRST_REVERSED, + DATA_TAGS, + MIXED, + P, + PLAIN, + ROLES, + TAGS_FIRST, + Arrangement, + make_table, +) # --- The public names this feature adds, in one place --------------------------------- @@ -217,21 +228,33 @@ def test_run_async_returns_the_same_summary(store: Any) -> None: assert last_run(job) is summary +@function_pod(output_keys="reading") +def format_reading(p1: int, p2: str) -> str: + """Format a reading with both data columns.""" + return f"{p2}:{p1}" + + +@pytest.mark.parametrize("roles", ROLES) +@pytest.mark.parametrize( + "reverse_layout", [False, True], ids=["tags-first", "data-first"] +) @pytest.mark.parametrize("first_async_source", [None, "a", "b"], ids=["sync", "a", "b"]) def test_equal_inputs_report_the_work_each_source_did( first_async_source: str | None, + reverse_layout: bool, + roles: str, ) -> None: """Three sources share results, while async arrival determines who computes.""" source_ids = ("a", "b", "c") first_finished = asyncio.Event() first_rows = 0 - class GatedSource(DictSource): + class GatedSource(ArrowTableSource): @override async def async_iter_data( self, ) -> AsyncIterator[tuple[TagProtocol, DataProtocol]]: - if self.source_id != f"dict_v1:{first_async_source}": + if self.source_id != f"arrow_table_v1:{first_async_source}": _ = await first_finished.wait() async for row in super().async_iter_data(): yield row @@ -247,21 +270,32 @@ def on_data_end( cached: bool, ) -> None: nonlocal first_rows - if node_label == f"double_{first_async_source}": + if node_label == f"reading_{first_async_source}": first_rows += 1 if first_rows == 2: first_finished.set() + arrangement = Arrangement( + P.tags[::-1] if reverse_layout else P.tags, + DATA_FIRST_REVERSED if reverse_layout else TAGS_FIRST, + roles, + ) + tag_only: dict[str, bool | list[str]] = { + PLAIN: True, + DATA_TAGS: [], + MIXED: [P.mixed_plain], + } + table = make_table(P, arrangement, rows=[0, 1]) job = PipelineJob(name="equal_inputs", database=InMemoryArrowDatabase()) with job: for source_id in source_ids: source = GatedSource( - [{"k": "first", "x": 4}, {"k": "second", "x": 6}], - tag_columns=["k"], - tag_only_columns=True, + table, + tag_columns=arrangement.tag_order, + tag_only_columns=tag_only[roles], source_id=source_id, ) - _ = double.pod(source, label=f"double_{source_id}") + _ = format_reading.pod(source, label=f"reading_{source_id}") async def run_gated() -> RunSummary: return await asyncio.wait_for( @@ -270,23 +304,26 @@ async def run_gated() -> RunSummary: summary = job.run() if first_async_source is None else asyncio.run(run_gated()) computed_source = first_async_source or "a" + expected = [("a", 2, "m:7"), ("b", 1, "n:8")] for source_id in source_ids: - label = f"double_{source_id}" + label = f"reading_{source_id}" node = job.nodes[label] assert isinstance(node, FunctionJobNode) computed = source_id == computed_source assert node_counts(summary, label) == ((2, 0, 0) if computed else (0, 2, 0)) rows = [ - (tag.as_dict()["k"], data.as_dict()["y"]) for tag, data in node.iter_data() + (tag.as_dict()["t1"], tag.as_dict()["t2"], data.as_dict()["reading"]) + for tag, data in node.iter_data() ] - expected = [("first", 8), ("second", 12)] if first_async_source is None: assert rows == expected else: assert len(rows) == len(expected) assert set(rows) == set(expected) - for key, _ in expected: - ((trace_label, invocation),) = node.trace({"k": key}, "y").function_runs() + for t1, t2, _ in expected: + ((trace_label, invocation),) = node.trace( + {"t1": t1, "t2": t2}, "reading" + ).function_runs() assert trace_label == label assert invocation.computed_here is computed