Skip to content

Commit 11c6498

Browse files
committed
Add basic unittests for bulk group registration
1 parent 0817ed3 commit 11c6498

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
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: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ static Dependency::Ptr CreateDependency(Checkable::Ptr parent, Checkable::Ptr ch
2727

2828
static void RegisterDependency(Dependency::Ptr dep, const String& redundancyGroup)
2929
{
30+
std::vector<DependencyGroup::Ptr> changedGroups;
3031
dep->SetRedundancyGroup(redundancyGroup);
31-
dep->GetChild()->AddDependency(dep, true);
32+
dep->GetChild()->AddDependency(dep, &changedGroups);
3233
dep->GetParent()->AddReverseDependency(dep);
3334
}
3435

@@ -145,6 +146,53 @@ BOOST_AUTO_TEST_CASE(multi_parent)
145146
BOOST_CHECK(childHost->IsReachable() == false);
146147
}
147148

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

0 commit comments

Comments
 (0)