diff --git a/tests/unit/collection/test_lb.extended.cc b/tests/unit/collection/test_lb.extended.cc index 702891715d..3a1919060b 100644 --- a/tests/unit/collection/test_lb.extended.cc +++ b/tests/unit/collection/test_lb.extended.cc @@ -777,6 +777,68 @@ INSTANTIATE_TEST_SUITE_P( DumpUserdefinedDataExplode, TestDumpUserdefinedData, booleans ); +struct TestDumpAttributesFieldData : TestParallelHarnessParam { }; + +TEST_P(TestDumpAttributesFieldData, test_dump_attributes_json) { + bool is_attribute = GetParam(); + + auto this_node = vt::theContext()->getNode(); + auto num_nodes = vt::theContext()->getNumNodes(); + + vt::vrt::collection::CollectionProxy proxy; + auto const range = vt::Index1D(num_nodes * 1); + + // Construct a collection + runInEpochCollective([&] { + proxy = vt::theCollection()->constructCollective( + range, "test_dump_attributes_json" + ); + }); + + vt::vrt::collection::balance::LBDataHolder lbdh; + PhaseType phase = 0; + + { + lbdh.node_data_[phase]; + lbdh.node_comm_[phase]; + + vt::Index1D idx(this_node * 1); + auto elm_ptr = proxy(idx).tryGetLocalPtr(); + EXPECT_NE(elm_ptr, nullptr); + if (elm_ptr != nullptr) { + auto elm_id = elm_ptr->getElmID(); + elm_ptr->valInsert("intSample", 123, false, false, is_attribute); + elm_ptr->valInsert("doubleSample", 123.456, false, false, is_attribute); + elm_ptr->valInsert("stringSample", std::string("abc"), false, false, is_attribute); + + elm_ptr->collectAttributes( + [&](std::string const& key, auto val) { + lbdh.node_user_attributes_[phase][elm_id][key] = val->toVariant(); + } + ); + lbdh.node_data_[phase][elm_id].whole_phase_load = 1.0; + } + } + + auto json_str = getJsonStringForPhase(phase, lbdh); + fmt::print("{}\n", json_str); + if (is_attribute) { + EXPECT_NE(json_str.find("attributes"), std::string::npos); + EXPECT_NE(json_str.find("intSample"), std::string::npos); + EXPECT_NE(json_str.find("doubleSample"), std::string::npos); + EXPECT_NE(json_str.find("stringSample"), std::string::npos); + } else { + EXPECT_EQ(json_str.find("attributes"), std::string::npos); + EXPECT_EQ(json_str.find("intSample"), std::string::npos); + EXPECT_EQ(json_str.find("doubleSample"), std::string::npos); + EXPECT_EQ(json_str.find("stringSample"), std::string::npos); + } +} + +INSTANTIATE_TEST_SUITE_P( + DumpAttributesFieldDataExplode, TestDumpAttributesFieldData, booleans +); + struct SerializationTestCol : vt::Collection { template void serialize(SerializerT &s) { vt::Collection::serialize(s);