From 1241217f283237804915cf228054b017a342dd0f Mon Sep 17 00:00:00 2001 From: Kyle Knoepfel Date: Tue, 3 Nov 2026 17:10:10 -0600 Subject: [PATCH 1/3] test(core): extend registrar, resource, and join coverage --- test/core_misc_test.cpp | 19 ++++++++ test/multilayer_join_test.cpp | 86 +++++++++++++++++++++++++++++++++++ test/resources_test.cpp | 28 ++++++++++-- 3 files changed, 129 insertions(+), 4 deletions(-) diff --git a/test/core_misc_test.cpp b/test/core_misc_test.cpp index 836804139..0a013fcdf 100644 --- a/test/core_misc_test.cpp +++ b/test/core_misc_test.cpp @@ -266,3 +266,22 @@ TEST_CASE("Moving a registrar transfers node creation", "[core]") CHECK(errors.empty()); } + +TEST_CASE("A throwing registrar creator is not retried by the destructor", "[core]") +{ + using namespace phlex::detail; + + declared_outputs outputs; + std::vector errors; + int creations = 0; + { + registrar reg{outputs, errors}; + reg.set_creator([&](auto const&, auto const&) -> declared_output_ptr { + ++creations; + throw std::runtime_error{"creator failed"}; + }); + CHECK_THROWS_WITH(reg.set_output_product_suffixes({}), "creator failed"); + } + CHECK(creations == 1); + CHECK(errors.empty()); +} diff --git a/test/multilayer_join_test.cpp b/test/multilayer_join_test.cpp index 185007459..80a4b3b37 100644 --- a/test/multilayer_join_test.cpp +++ b/test/multilayer_join_test.cpp @@ -1,5 +1,7 @@ +#include "phlex/core/fold_join_node.hpp" #include "phlex/core/message.hpp" #include "phlex/core/multilayer_join_node.hpp" +#include "phlex/core/product_selector.hpp" #include "phlex/model/algorithm_name.hpp" #include "phlex/model/fwd.hpp" #include "phlex/model/identifier.hpp" @@ -10,7 +12,13 @@ #include #include +#include +#include +#include +#include +#include #include +#include #include #include @@ -73,6 +81,8 @@ TEST_CASE("multilayer_join_node joins multiple input products", "[join]") auto& left_port = receiver_for<0ull, 2>(join, 0u); auto& right_port = receiver_for<0ull, 2>(join, 1u); + CHECK_THROWS_AS(receiver_for<0ull>(join, 2u), std::runtime_error); + REQUIRE(left_port.try_put({.store = left_store, .id = message_id})); graph.wait_for_all(); @@ -85,6 +95,10 @@ TEST_CASE("multilayer_join_node joins multiple input products", "[join]") auto index_ports = join.index_ports(); REQUIRE(index_ports.size() == 2u); + CHECK(index_ports[0].layer == "left_layer"_id); + CHECK(index_ports[1].layer == "right_layer"_id); + CHECK_FALSE(index_ports[0].counting_layer.has_value()); + CHECK_FALSE(index_ports[1].counting_layer.has_value()); REQUIRE(index_ports[0].index_port->try_put( {.index = left_store->index(), .msg_id = message_id, .cache = true})); graph.wait_for_all(); @@ -110,3 +124,75 @@ TEST_CASE("multilayer_join_node joins multiple input products", "[join]") REQUIRE(index_ports[1].token_port->try_put({.index = right_store->index(), .count = 1})); graph.wait_for_all(); } + +TEST_CASE("Same-layer joins wait for all inputs and preserve selector order", "[join]") +{ + tbb::flow::graph graph; + multilayer_join_node<3> join{graph, "same_layer_join", {"event"_id, "event"_id, "event"_id}}; + CHECK(join.index_ports().empty()); + + auto const left_creator = algorithm_name::create("left"); + auto const middle_creator = algorithm_name::create("middle"); + auto const right_creator = algorithm_name::create("right"); + + product_selectors const selectors{{.creator = left_creator.to_string()}, + {.creator = middle_creator.to_string()}, + {.creator = right_creator.to_string()}}; + auto const stage = "test"_id; + std::array const stores{product_store::base(&left_creator, &stage), + product_store::base(&middle_creator, &stage), + product_store::base(&right_creator, &stage)}; + tbb::flow::queue_node> sink{graph}; + + using internal::receiver_for; + auto try_put_for_receiver = [&join, &selectors, &stores](std::size_t const index) { + return receiver_for<3>(join, selectors, selectors[index]) + .try_put({.store = stores.at(index), .id = message_id}); + }; + + make_edge(output_port<0>(join), sink); + REQUIRE(try_put_for_receiver(2)); + REQUIRE(try_put_for_receiver(0)); + graph.wait_for_all(); + message_tuple<3> output; + CHECK_FALSE(sink.try_get(output)); + REQUIRE(try_put_for_receiver(1)); + graph.wait_for_all(); + REQUIRE(sink.try_get(output)); + CHECK(std::get<0>(output).id == message_id); + CHECK(std::get<1>(output).id == message_id); + CHECK(std::get<2>(output).id == message_id); + CHECK(std::get<0>(output).store == stores[0]); + CHECK(std::get<1>(output).store == stores[1]); + CHECK(std::get<2>(output).store == stores[2]); + CHECK_FALSE(sink.try_get(output)); + CHECK_THROWS_AS(receiver_for<3>(join, selectors, {.creator = "missing"_id}), std::runtime_error); +} + +TEST_CASE("Fold join data receivers exclude the partition port", "[join]") +{ + tbb::flow::graph graph; + auto const name = algorithm_name::create("fold_join_test"); + fold_join_node join{graph, + name, + "test_stage"_id, + "job"_id, + {"event"_id, "run"_id}, + product_specifications(1), + [](data_cell_index const&) { return std::make_unique(0); }}; + CHECK_THROWS_AS(receiver_for<1ull>(join, 2u), std::runtime_error); + CHECK_THROWS_AS(receiver_for<1ull>(join, std::numeric_limits::max()), + std::runtime_error); + product_selectors const selectors{{.creator = "left"_id}, {.creator = "right"_id}}; + CHECK(&receiver_for(join, selectors, selectors[0]) == &input_port<1>(join)); + CHECK(&receiver_for(join, selectors, selectors[1]) == &input_port<2>(join)); + + auto const ports = join.index_ports(); + REQUIRE(ports.size() == 3); + CHECK(ports[0].layer == "job"_id); + CHECK(ports[0].counting_layer == "event"_id); + CHECK(ports[1].layer == "event"_id); + CHECK(ports[1].counting_layer == "event"_id); + CHECK(ports[2].layer == "run"_id); + CHECK(ports[2].counting_layer == "run"_id); +} diff --git a/test/resources_test.cpp b/test/resources_test.cpp index 8a525ae67..65298e185 100644 --- a/test/resources_test.cpp +++ b/test/resources_test.cpp @@ -44,6 +44,16 @@ namespace { struct default_unlimited_resource {}; + struct counted_unlimited_resource { + explicit counted_unlimited_resource(int& constructions) { ++constructions; } + }; + + struct counted_serialized_resource { + using token_type = counted_serialized_resource const*; + + explicit counted_serialized_resource(int& constructions) { ++constructions; } + }; + struct invalid_serialized_resource { using token_type = int*; }; @@ -276,18 +286,28 @@ TEST_CASE("resource catalog", "[resource]") SECTION("duplicate serialized registrations throw") { - catalog.add_serialized(); - CHECK_THROWS_WITH(catalog.add_serialized(), + int constructions = 0; + catalog.add_serialized(constructions); + auto& limiter = catalog.limiter_for(); + CHECK(constructions == 1); + CHECK_THROWS_WITH(catalog.add_serialized(constructions), Catch::Matchers::ContainsSubstring("Resource of type '") && Catch::Matchers::ContainsSubstring("' has already been registered")); + CHECK(constructions == 1); + CHECK(&catalog.limiter_for() == &limiter); } SECTION("duplicate unlimited registrations throw") { - catalog.add_unlimited(42); - CHECK_THROWS_WITH(catalog.add_unlimited(43), + int constructions = 0; + catalog.add_unlimited(constructions); + auto const resource = catalog.access_for(); + CHECK(constructions == 1); + CHECK_THROWS_WITH(catalog.add_unlimited(constructions), Catch::Matchers::ContainsSubstring("Resource of type '") && Catch::Matchers::ContainsSubstring("' has already been registered")); + CHECK(constructions == 1); + CHECK(catalog.access_for() == resource); } SECTION("missing resources throw") From 863e13370150c71fe8aafad109b9ebd17f6fe487 Mon Sep 17 00:00:00 2001 From: Kyle Knoepfel Date: Thu, 12 Nov 2026 12:02:53 -0600 Subject: [PATCH 2/3] test(core): verify join ID matching and clarify test scenarios Aided by GPT-6.1 Sol --- test/multilayer_join_test.cpp | 115 +++++++++++++++++++++++++--------- test/resources_test.cpp | 4 +- 2 files changed, 89 insertions(+), 30 deletions(-) diff --git a/test/multilayer_join_test.cpp b/test/multilayer_join_test.cpp index 80a4b3b37..4db9e1eeb 100644 --- a/test/multilayer_join_test.cpp +++ b/test/multilayer_join_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -125,7 +126,7 @@ TEST_CASE("multilayer_join_node joins multiple input products", "[join]") graph.wait_for_all(); } -TEST_CASE("Same-layer joins wait for all inputs and preserve selector order", "[join]") +TEST_CASE("Same-layer join receiver lookup and input ordering", "[join]") { tbb::flow::graph graph; multilayer_join_node<3> join{graph, "same_layer_join", {"event"_id, "event"_id, "event"_id}}; @@ -151,25 +152,77 @@ TEST_CASE("Same-layer joins wait for all inputs and preserve selector order", "[ }; make_edge(output_port<0>(join), sink); - REQUIRE(try_put_for_receiver(2)); - REQUIRE(try_put_for_receiver(0)); + SECTION("joins wait for all inputs and preserve selector order") + { + REQUIRE(try_put_for_receiver(2)); + REQUIRE(try_put_for_receiver(0)); + graph.wait_for_all(); + message_tuple<3> output; + CHECK_FALSE(sink.try_get(output)); + REQUIRE(try_put_for_receiver(1)); + graph.wait_for_all(); + REQUIRE(sink.try_get(output)); + CHECK(std::get<0>(output).id == message_id); + CHECK(std::get<1>(output).id == message_id); + CHECK(std::get<2>(output).id == message_id); + CHECK(std::get<0>(output).store == stores[0]); + CHECK(std::get<1>(output).store == stores[1]); + CHECK(std::get<2>(output).store == stores[2]); + CHECK_FALSE(sink.try_get(output)); + } + + SECTION("receiver lookup rejects unknown selectors") + { + CHECK_THROWS_AS(receiver_for<3>(join, selectors, {.creator = "missing"_id}), + std::runtime_error); + } +} + +TEST_CASE("Same-layer joins match message IDs rather than arrival order", "[join]") +{ + tbb::flow::graph graph; + multilayer_join_node<3> join{graph, "same_layer_id_join", {"event"_id, "event"_id, "event"_id}}; + tbb::flow::queue_node> sink{graph}; + make_edge(output_port<0>(join), sink); + + auto try_put = [&join](std::array const message_ids) { + unsigned int valid_puts = 0; + // This test verifies ID matching, so real product stores are unnecessary. + valid_puts += receiver_for<0ull, 3>(join, 0).try_put({.id = message_ids[0]}); + valid_puts += receiver_for<1ull, 3>(join, 1).try_put({.id = message_ids[1]}); + valid_puts += receiver_for<2ull, 3>(join, 2).try_put({.id = message_ids[2]}); + return valid_puts == 3u; + }; + + // Every port has a message, but neither ID has a complete input set. + REQUIRE(try_put({42u, 42u, 43u})); graph.wait_for_all(); message_tuple<3> output; CHECK_FALSE(sink.try_get(output)); - REQUIRE(try_put_for_receiver(1)); + + REQUIRE(try_put({43u, 43u, 42u})); graph.wait_for_all(); - REQUIRE(sink.try_get(output)); - CHECK(std::get<0>(output).id == message_id); - CHECK(std::get<1>(output).id == message_id); - CHECK(std::get<2>(output).id == message_id); - CHECK(std::get<0>(output).store == stores[0]); - CHECK(std::get<1>(output).store == stores[1]); - CHECK(std::get<2>(output).store == stores[2]); + + // Only two complete sets of messages should be produced. + std::vector> outputs; + CHECK(sink.try_get(output)); + outputs.push_back(output); + CHECK(sink.try_get(output)); + outputs.push_back(output); CHECK_FALSE(sink.try_get(output)); - CHECK_THROWS_AS(receiver_for<3>(join, selectors, {.creator = "missing"_id}), std::runtime_error); + + // All message IDs should agree per output + std::set consumed_message_ids; + for (auto const& [msg0, msg1, msg2] : outputs) { + CHECK(msg0.id == msg1.id); + CHECK(msg1.id == msg2.id); + consumed_message_ids.insert(msg0.id); + } + + CHECK(consumed_message_ids == std::set{42u, 43u}); } -TEST_CASE("Fold join data receivers exclude the partition port", "[join]") +TEST_CASE("Fold join receiver lookup and index metadata", "[join]") { tbb::flow::graph graph; auto const name = algorithm_name::create("fold_join_test"); @@ -180,19 +233,25 @@ TEST_CASE("Fold join data receivers exclude the partition port", "[join]") {"event"_id, "run"_id}, product_specifications(1), [](data_cell_index const&) { return std::make_unique(0); }}; - CHECK_THROWS_AS(receiver_for<1ull>(join, 2u), std::runtime_error); - CHECK_THROWS_AS(receiver_for<1ull>(join, std::numeric_limits::max()), - std::runtime_error); - product_selectors const selectors{{.creator = "left"_id}, {.creator = "right"_id}}; - CHECK(&receiver_for(join, selectors, selectors[0]) == &input_port<1>(join)); - CHECK(&receiver_for(join, selectors, selectors[1]) == &input_port<2>(join)); - - auto const ports = join.index_ports(); - REQUIRE(ports.size() == 3); - CHECK(ports[0].layer == "job"_id); - CHECK(ports[0].counting_layer == "event"_id); - CHECK(ports[1].layer == "event"_id); - CHECK(ports[1].counting_layer == "event"_id); - CHECK(ports[2].layer == "run"_id); - CHECK(ports[2].counting_layer == "run"_id); + SECTION("data receivers exclude the partition port and reject invalid indices") + { + CHECK_THROWS_AS(receiver_for<1ull>(join, 2u), std::runtime_error); + CHECK_THROWS_AS(receiver_for<1ull>(join, std::numeric_limits::max()), + std::runtime_error); + product_selectors const selectors{{.creator = "left"_id}, {.creator = "right"_id}}; + CHECK(&receiver_for(join, selectors, selectors[0]) == &input_port<1>(join)); + CHECK(&receiver_for(join, selectors, selectors[1]) == &input_port<2>(join)); + } + + SECTION("index ports identify routing and counting layers with the deepest input first") + { + auto const ports = join.index_ports(); + REQUIRE(ports.size() == 3); + CHECK(ports[0].layer == "job"_id); + CHECK(ports[0].counting_layer == "event"_id); + CHECK(ports[1].layer == "event"_id); + CHECK(ports[1].counting_layer == "event"_id); + CHECK(ports[2].layer == "run"_id); + CHECK(ports[2].counting_layer == "run"_id); + } } diff --git a/test/resources_test.cpp b/test/resources_test.cpp index 65298e185..e4b3620ab 100644 --- a/test/resources_test.cpp +++ b/test/resources_test.cpp @@ -284,7 +284,7 @@ TEST_CASE("resource catalog", "[resource]") CHECK_NOTHROW(catalog.limiter_for()); } - SECTION("duplicate serialized registrations throw") + SECTION("duplicate serialized registrations throw without constructing another resource") { int constructions = 0; catalog.add_serialized(constructions); @@ -297,7 +297,7 @@ TEST_CASE("resource catalog", "[resource]") CHECK(&catalog.limiter_for() == &limiter); } - SECTION("duplicate unlimited registrations throw") + SECTION("duplicate unlimited registrations throw without constructing another resource") { int constructions = 0; catalog.add_unlimited(constructions); From 7932006b3ee2ae9ffd8f9bad2cd6cfa0a985a553 Mon Sep 17 00:00:00 2001 From: Chris Green Date: Mon, 23 Nov 2026 17:43:48 -0600 Subject: [PATCH 3/3] test(join): fixes required by upstream API/requirement changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use direct construction for `algorithm_name` instead of the removed `create` factory. - Construct product specifications from the fold join test’s named algorithm. --- test/multilayer_join_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/multilayer_join_test.cpp b/test/multilayer_join_test.cpp index 4db9e1eeb..ca5a55e97 100644 --- a/test/multilayer_join_test.cpp +++ b/test/multilayer_join_test.cpp @@ -132,9 +132,9 @@ TEST_CASE("Same-layer join receiver lookup and input ordering", "[join]") multilayer_join_node<3> join{graph, "same_layer_join", {"event"_id, "event"_id, "event"_id}}; CHECK(join.index_ports().empty()); - auto const left_creator = algorithm_name::create("left"); - auto const middle_creator = algorithm_name::create("middle"); - auto const right_creator = algorithm_name::create("right"); + auto const left_creator = algorithm_name{"left"}; + auto const middle_creator = algorithm_name{"middle"}; + auto const right_creator = algorithm_name{"right"}; product_selectors const selectors{{.creator = left_creator.to_string()}, {.creator = middle_creator.to_string()}, @@ -225,13 +225,13 @@ TEST_CASE("Same-layer joins match message IDs rather than arrival order", "[join TEST_CASE("Fold join receiver lookup and index metadata", "[join]") { tbb::flow::graph graph; - auto const name = algorithm_name::create("fold_join_test"); + auto const name = algorithm_name{"fold_join_test"}; fold_join_node join{graph, name, "test_stage"_id, "job"_id, {"event"_id, "run"_id}, - product_specifications(1), + product_specifications{spec(name)}, [](data_cell_index const&) { return std::make_unique(0); }}; SECTION("data receivers exclude the partition port and reject invalid indices") {