Skip to content

Commit

Permalink
#2229: Add unit test for dumping attributes field in json data file
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Feb 16, 2024
1 parent c6cdb4a commit e4323d4
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/unit/collection/test_lb.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,68 @@ INSTANTIATE_TEST_SUITE_P(
DumpUserdefinedDataExplode, TestDumpUserdefinedData, booleans
);

struct TestDumpAttributesFieldData : TestParallelHarnessParam<bool> { };

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<MyCol> proxy;
auto const range = vt::Index1D(num_nodes * 1);

// Construct a collection
runInEpochCollective([&] {
proxy = vt::theCollection()->constructCollective<MyCol>(
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<SerializationTestCol, vt::Index1D> {
template <typename SerializerT> void serialize(SerializerT &s) {
vt::Collection<SerializationTestCol, vt::Index1D>::serialize(s);
Expand Down

0 comments on commit e4323d4

Please sign in to comment.