Skip to content

Commit fe559ef

Browse files
committed
Add basic unittests for bulk group registration
1 parent 47a1130 commit fe559ef

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ add_boost_test(base
230230
icinga_checkresult/service_flapping_notification
231231
icinga_checkresult/suppressed_notification
232232
icinga_dependencies/multi_parent
233+
icinga_dependencies/push_dependency_groups_to_registry
233234
icinga_dependencies/default_redundancy_group_registration_unregistration
234235
icinga_dependencies/simple_redundancy_group_registration_unregistration
235236
icinga_dependencies/mixed_redundancy_group_registration_unregsitration

test/icinga-dependencies.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,53 @@ BOOST_AUTO_TEST_CASE(multi_parent)
145145
BOOST_CHECK(childHost->IsReachable() == false);
146146
}
147147

148+
BOOST_AUTO_TEST_CASE(push_dependency_groups_to_registry)
149+
{
150+
Checkable::Ptr childHostC(CreateHost("C"));
151+
Checkable::Ptr childHostD(CreateHost("D"));
152+
std::set<Dependency::Ptr> dependencies; // Keep track of all dependencies to avoid unexpected deletions.
153+
for (auto& parent : {String("A"), String("B"), String("E")}) {
154+
Dependency::Ptr depC(CreateDependency(CreateHost(parent), childHostC, "depC" + parent));
155+
Dependency::Ptr depD(CreateDependency(depC->GetParent(), childHostD, "depD" + parent));
156+
if (parent == "A") {
157+
Dependency::Ptr depCA2(CreateDependency(depC->GetParent(), childHostC, "depCA2"));
158+
childHostC->AddDependency(depCA2);
159+
dependencies.emplace(depCA2);
160+
} else {
161+
depC->SetRedundancyGroup("redundant", true);
162+
depD->SetRedundancyGroup("redundant", true);
163+
164+
if (parent == "B") { // Create an exact duplicate of depC, but with a different name.
165+
Dependency::Ptr depCB2(CreateDependency(depC->GetParent(), childHostC, "depCB2"));
166+
depCB2->SetRedundancyGroup("redundant", true);
167+
childHostC->AddDependency(depCB2);
168+
dependencies.emplace(depCB2);
169+
}
170+
}
171+
childHostC->AddDependency(depC);
172+
childHostD->AddDependency(depD);
173+
dependencies.insert({depC, depD});
174+
}
175+
176+
childHostC->PushDependencyGroupsToRegistry();
177+
childHostD->PushDependencyGroupsToRegistry();
178+
179+
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
180+
BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());
181+
for (auto& checkable : {childHostC, childHostD}) {
182+
BOOST_CHECK_EQUAL(2, checkable->GetDependencyGroups().size());
183+
for (auto& dependencyGroup : checkable->GetDependencyGroups()) {
184+
if (dependencyGroup->IsRedundancyGroup()) {
185+
BOOST_CHECK_EQUAL(5, dependencyGroup->GetMemberCount());
186+
BOOST_CHECK_EQUAL(checkable == childHostC ? 5 : 3, checkable->GetDependencies().size());
187+
} else {
188+
BOOST_CHECK_EQUAL(3, dependencyGroup->GetMemberCount());
189+
BOOST_CHECK_EQUAL(checkable == childHostC ? 5 : 3, checkable->GetDependencies().size());
190+
}
191+
}
192+
}
193+
}
194+
148195
BOOST_AUTO_TEST_CASE(default_redundancy_group_registration_unregistration)
149196
{
150197
Checkable::Ptr childHostC(CreateHost("C"));

0 commit comments

Comments
 (0)