Skip to content

Commit

Permalink
#2162: Fix vt aborting when lb file dont have metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Jun 20, 2023
1 parent 990919d commit 741ab5b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 31 deletions.
64 changes: 33 additions & 31 deletions src/vt/vrt/collection/balance/lb_data_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,41 +374,43 @@ LBDataHolder::LBDataHolder(nlohmann::json const& j)
}

void LBDataHolder::readMetadata(nlohmann::json const& j) {
auto metadata = j["metadata"];
if (metadata.find("phases") != metadata.end()) {
auto phases = metadata["phases"];
// load count
vtAssertExpr(phases["count"].is_number());
count_ = phases["count"];
// load all skipped phases
auto sl = phases["skipped"]["list"];
if(sl.is_array()) {
for(PhaseType skipped : sl) {
skipped_phases_.insert(skipped);
if (j.find("metadata") != j.end()) {
auto metadata = j["metadata"];
if (metadata.find("phases") != metadata.end()) {
auto phases = metadata["phases"];
// load count
vtAssertExpr(phases["count"].is_number());
count_ = phases["count"];
// load all skipped phases
auto sl = phases["skipped"]["list"];
if(sl.is_array()) {
for(PhaseType skipped : sl) {
skipped_phases_.insert(skipped);
}
}
}
auto sr = phases["skipped"]["range"];
if(sr.is_array()) {
for(auto const& pair : sr) {
vtAssertExpr(pair.is_array());
for(PhaseType i = pair[0]; i <= pair[1]; i++){
skipped_phases_.insert(i);
auto sr = phases["skipped"]["range"];
if(sr.is_array()) {
for(auto const& pair : sr) {
vtAssertExpr(pair.is_array());
for(PhaseType i = pair[0]; i <= pair[1]; i++){
skipped_phases_.insert(i);
}
}
}
}
// load all identical phases
auto il = phases["identical_to_previous"]["list"];
if(il.is_array()) {
for(PhaseType identical : il) {
identical_phases_.insert(identical);
// load all identical phases
auto il = phases["identical_to_previous"]["list"];
if(il.is_array()) {
for(PhaseType identical : il) {
identical_phases_.insert(identical);
}
}
}
auto ir = phases["identical_to_previous"]["range"];
if(ir.is_array()) {
for(auto const& pair : ir) {
vtAssertExpr(pair.is_array());
for(PhaseType i = pair[0]; i <= pair[1]; i++){
identical_phases_.insert(i);
auto ir = phases["identical_to_previous"]["range"];
if(ir.is_array()) {
for(auto const& pair : ir) {
vtAssertExpr(pair.is_array());
for(PhaseType i = pair[0]; i <= pair[1]; i++){
identical_phases_.insert(i);
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/collection/test_lb_data_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ void addPhasesDataToJson(nlohmann::json& json, PhaseType amountOfPhasesToAdd, st
json["phases"] = phases;
}

TEST_F(TestOptionalPhasesMetadata, test_no_metadata) {
using LBDataHolder = vt::vrt::collection::balance::LBDataHolder;

nlohmann::json json;
addPhasesDataToJson(json, num_phases, {});

LBDataHolder testObj(json);
EXPECT_EQ(testObj.count_, num_phases);
std::set<PhaseType> expectedSkipped = {};
EXPECT_EQ(testObj.skipped_phases_, expectedSkipped);
std::set<PhaseType> expectedIdentical = {};
EXPECT_EQ(testObj.identical_phases_, expectedIdentical);

auto outJsonPtr = testObj.metadataToJson();
ASSERT_TRUE(outJsonPtr != nullptr);

EXPECT_EQ((*outJsonPtr)["count"], num_phases);
std::vector<PhaseType> expectedSkippedList = {};
EXPECT_EQ((*outJsonPtr)["skipped"]["list"], expectedSkippedList);
std::vector<std::pair<PhaseType, PhaseType>> expectedSkippedRanges = {};
EXPECT_EQ((*outJsonPtr)["skipped"]["range"], expectedSkippedRanges);
std::vector<PhaseType> expectedIdenticalList = {};
EXPECT_EQ((*outJsonPtr)["identical_to_previous"]["list"], expectedIdenticalList);
std::vector<std::pair<PhaseType, PhaseType>> expectedIdenticalRanges = {};
EXPECT_EQ((*outJsonPtr)["identical_to_previous"]["range"], expectedIdenticalRanges);
}

TEST_F(TestOptionalPhasesMetadata, test_no_lb_phases_metadata) {
using LBDataHolder = vt::vrt::collection::balance::LBDataHolder;

Expand Down

0 comments on commit 741ab5b

Please sign in to comment.