File: icinga-dependencies.cpp

package info (click to toggle)
icinga2 2.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,032 kB
  • sloc: cpp: 97,877; sql: 3,261; cs: 1,636; yacc: 1,584; sh: 1,009; ansic: 890; lex: 420; python: 80; makefile: 62; javascript: 12
file content (435 lines) | stat: -rw-r--r-- 19,532 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */

#include "icinga/host.hpp"
#include "icinga/dependency.hpp"
#include <BoostTestTargetConfig.h>
#include <iostream>

using namespace icinga;

BOOST_AUTO_TEST_SUITE(icinga_dependencies)

static Host::Ptr CreateHost(const std::string& name, bool pushDependencyGroupsToRegistry = true)
{
	Host::Ptr host = new Host();
	host->SetName(name);
	if (pushDependencyGroupsToRegistry) {
		host->PushDependencyGroupsToRegistry();
	}
	return host;
}

static Dependency::Ptr CreateDependency(Checkable::Ptr parent, Checkable::Ptr child, const String& name)
{
	Dependency::Ptr dep = new Dependency();
	dep->SetParent(parent);
	dep->SetChild(child);
	dep->SetName(name + "!" + child->GetName());
	return dep;
}

static void RegisterDependency(Dependency::Ptr dep, const String& redundancyGroup)
{
	dep->SetRedundancyGroup(redundancyGroup);
	dep->GetChild()->AddDependency(dep);
	dep->GetParent()->AddReverseDependency(dep);
}

static void AssertCheckableRedundancyGroup(Checkable::Ptr checkable, int dependencyCount, int groupCount, int totalDependenciesCount)
{
	BOOST_CHECK_MESSAGE(
		dependencyCount == checkable->GetDependencies().size(),
		"Dependency count mismatch for '" << checkable->GetName() << "' - expected=" << dependencyCount << "; got="
			<< checkable->GetDependencies().size()
	);
	auto dependencyGroups(checkable->GetDependencyGroups());
	BOOST_CHECK_MESSAGE(
		groupCount == dependencyGroups.size(),
		"Dependency group count mismatch for '" << checkable->GetName() << "' - expected=" << groupCount
			<< "; got=" << dependencyGroups.size()
	);

	for (auto& dependencyGroup : dependencyGroups) {
		BOOST_CHECK_MESSAGE(
			totalDependenciesCount == dependencyGroup->GetDependenciesCount(),
			"Dependency group '" << dependencyGroup->GetRedundancyGroupName() << "' and Checkable '" << checkable->GetName()
				<< "' total dependencies count mismatch - expected=" << totalDependenciesCount << "; got="
				<< dependencyGroup->GetDependenciesCount()
		);
	}

	if (groupCount > 0) {
		BOOST_REQUIRE_MESSAGE(!dependencyGroups.empty(), "Checkable '" << checkable->GetName() << "' should have at least one dependency group.");
	}
}

static std::vector<DependencyGroup::Ptr> ExtractGroups(const Checkable::Ptr& checkable)
{
	auto dependencyGroups(checkable->GetDependencyGroups());
	std::sort(dependencyGroups.begin(), dependencyGroups.end());
	return dependencyGroups;
}

BOOST_AUTO_TEST_CASE(multi_parent)
{
	/* One child host, two parent hosts. Simulate multi-parent dependencies. */
	std::cout << "Testing reachability for multi parent dependencies." << std::endl;

	/*
	 * Our mock requires:
	 * - SetParent/SetChild functions for the dependency
	 * - Parent objects need a CheckResult object
	 * - Dependencies need a StateFilter
	 */
	Host::Ptr parentHost1 = CreateHost("parentHost1");
	parentHost1->SetStateRaw(ServiceCritical);
	parentHost1->SetStateType(StateTypeHard);
	parentHost1->SetLastCheckResult(new CheckResult());

	Host::Ptr parentHost2 = CreateHost("parentHost2");
	parentHost2->SetStateRaw(ServiceOK);
	parentHost2->SetStateType(StateTypeHard);
	parentHost2->SetLastCheckResult(new CheckResult());

	Host::Ptr childHost = CreateHost("childHost");
	childHost->SetStateRaw(ServiceOK);
	childHost->SetStateType(StateTypeHard);

	/* Build the dependency tree. */
	Dependency::Ptr dep1 (CreateDependency(parentHost1, childHost, "dep1"));
	dep1->SetStateFilter(StateFilterUp);
	RegisterDependency(dep1, "");

	Dependency::Ptr dep2 (CreateDependency(parentHost2, childHost, "dep2"));
	dep2->SetStateFilter(StateFilterUp);
	RegisterDependency(dep2, "");

	/* Test the reachability from this point.
	 * parentHost1 is DOWN, parentHost2 is UP.
	 * Expected result: childHost is unreachable.
	 */
	parentHost1->SetStateRaw(ServiceCritical); // parent Host 1 DOWN
	parentHost2->SetStateRaw(ServiceOK);       // parent Host 2 UP

	BOOST_CHECK(childHost->IsReachable() == false);

	Dependency::Ptr duplicateDep (CreateDependency(parentHost1, childHost, "dep4"));
	duplicateDep->SetIgnoreSoftStates(false, true);
	RegisterDependency(duplicateDep, "");
	parentHost1->SetStateType(StateTypeSoft);

	// It should still be unreachable, due to the duplicated dependency object above with ignore_soft_states set to false.
	BOOST_CHECK(childHost->IsReachable() == false);
	parentHost1->SetStateType(StateTypeHard);
	childHost->RemoveDependency(duplicateDep);

	/* The only DNS server is DOWN.
	 * Expected result: childHost is unreachable.
	 */
	childHost->RemoveDependency(dep1); // Remove the dep and re-add it with a configured redundancy group.
	RegisterDependency(dep1, "DNS");
	BOOST_CHECK(childHost->IsReachable() == false);

	/* 1/2 DNS servers is DOWN.
	 * Expected result: childHost is reachable.
	 */
	childHost->RemoveDependency(dep2);
	RegisterDependency(dep2, "DNS");
	BOOST_CHECK(childHost->IsReachable() == true);

	auto grandParentHost(CreateHost("GrandParentHost"));
	grandParentHost->SetLastCheckResult(new CheckResult());
	grandParentHost->SetStateRaw(ServiceCritical);
	grandParentHost->SetStateType(StateTypeHard);

	Dependency::Ptr dep3 (CreateDependency(grandParentHost, parentHost1, "dep3"));
	dep3->SetStateFilter(StateFilterUp);
	RegisterDependency(dep3, "");
	// The grandparent is DOWN but the DNS redundancy group has to be still reachable.
	BOOST_CHECK_EQUAL(true, childHost->IsReachable());
	childHost->RemoveDependency(dep3);

	/* Both DNS servers are DOWN.
	 * Expected result: childHost is unreachable.
	 */
	parentHost1->SetStateRaw(ServiceCritical); // parent Host 1 DOWN
	parentHost2->SetStateRaw(ServiceCritical); // parent Host 2 DOWN

	BOOST_CHECK(childHost->IsReachable() == false);
}

BOOST_AUTO_TEST_CASE(push_dependency_groups_to_registry)
{
	Checkable::Ptr childHostC(CreateHost("C", false));
	Checkable::Ptr childHostD(CreateHost("D", false));
	std::set<Dependency::Ptr> dependencies; // Keep track of all dependencies to avoid unexpected deletions.
	for (auto& parent : {String("A"), String("B"), String("E")}) {
		Dependency::Ptr depC(CreateDependency(CreateHost(parent), childHostC, "depC" + parent));
		Dependency::Ptr depD(CreateDependency(depC->GetParent(), childHostD, "depD" + parent));
		if (parent == "A") {
			Dependency::Ptr depCA2(CreateDependency(depC->GetParent(), childHostC, "depCA2"));
			childHostC->AddDependency(depCA2);
			dependencies.emplace(depCA2);
		} else {
			depC->SetRedundancyGroup("redundant", true);
			depD->SetRedundancyGroup("redundant", true);

			if (parent == "B") { // Create an exact duplicate of depC, but with a different name.
				Dependency::Ptr depCB2(CreateDependency(depC->GetParent(), childHostC, "depCB2"));
				depCB2->SetRedundancyGroup("redundant", true);
				childHostC->AddDependency(depCB2);
				dependencies.emplace(depCB2);
			}
		}
		childHostC->AddDependency(depC);
		childHostD->AddDependency(depD);
		dependencies.insert({depC, depD});
	}

	childHostC->PushDependencyGroupsToRegistry();
	childHostD->PushDependencyGroupsToRegistry();

	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());
	for (auto& checkable : {childHostC, childHostD}) {
		BOOST_CHECK_EQUAL(2, checkable->GetDependencyGroups().size());
		for (auto& dependencyGroup : checkable->GetDependencyGroups()) {
			if (dependencyGroup->IsRedundancyGroup()) {
				BOOST_CHECK_EQUAL(5, dependencyGroup->GetDependenciesCount());
				BOOST_CHECK_EQUAL(checkable == childHostC ? 5 : 3, checkable->GetDependencies().size());
			} else {
				BOOST_CHECK_EQUAL(3, dependencyGroup->GetDependenciesCount());
				BOOST_CHECK_EQUAL(checkable == childHostC ? 5 : 3, checkable->GetDependencies().size());
			}
		}
	}
}

BOOST_AUTO_TEST_CASE(default_redundancy_group_registration_unregistration)
{
	Checkable::Ptr childHostC(CreateHost("C"));
	Dependency::Ptr depCA(CreateDependency(CreateHost("A"), childHostC, "depCA"));
	RegisterDependency(depCA, "");
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 1);
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depCB(CreateDependency(CreateHost("B"), childHostC, "depCB"));
	RegisterDependency(depCB, "");
	AssertCheckableRedundancyGroup(childHostC, 2, 2, 1);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	Checkable::Ptr childHostD(CreateHost("D"));
	Dependency::Ptr depDA(CreateDependency(depCA->GetParent(), childHostD, "depDA"));
	RegisterDependency(depDA, "");
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depDB(CreateDependency(depCB->GetParent(), childHostD, "depDB"));
	RegisterDependency(depDB, "");
	AssertCheckableRedundancyGroup(childHostD, 2, 2, 2);
	AssertCheckableRedundancyGroup(childHostC, 2, 2, 2);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	// This is an exact duplicate of depCA, but with a different dependency name.
	Dependency::Ptr depCA2(CreateDependency(depCA->GetParent(), childHostC, "depCA2"));
	// This is a duplicate of depCA, but with a different state filter.
	Dependency::Ptr depCA3(CreateDependency(depCA->GetParent(), childHostC, "depCA3"));
	depCA3->SetStateFilter(StateFilterUp, true);
	// This is a duplicate of depCA, but with a different ignore_soft_states flag.
	Dependency::Ptr depCA4(CreateDependency(depCA->GetParent(), childHostC, "depCA4"));
	depCA4->SetIgnoreSoftStates(false, true);

	for (auto& dependency : {depCA2, depCA3, depCA4}) {
		bool isAnExactDuplicate = dependency == depCA2;
		RegisterDependency(dependency, "");

		if (isAnExactDuplicate) {
			BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
		}

		for (auto& dependencyGroup : childHostD->GetDependencyGroups()) {
			if (dependency->GetParent() == dependencyGroup->GetDependenciesForChild(childHostD.get()).front()->GetParent()) {
				BOOST_CHECK_EQUAL(isAnExactDuplicate ? 3 : 1, dependencyGroup->GetDependenciesCount());
			} else {
				BOOST_CHECK_EQUAL(2, dependencyGroup->GetDependenciesCount());
			}
			BOOST_CHECK_EQUAL(2, childHostD->GetDependencies().size());
		}

		for (auto& dependencyGroup : childHostC->GetDependencyGroups()) {
			if (dependency->GetParent() == dependencyGroup->GetDependenciesForChild(childHostC.get()).front()->GetParent()) {
				// If depCA2 is currently being processed, then the group should have 3 dependencies, that's because
				// depCA2 is an exact duplicate of depCA, and depCA shares the same group with depDA.
				BOOST_CHECK_EQUAL(isAnExactDuplicate ? 3 : 2, dependencyGroup->GetDependenciesCount());
			} else {
				BOOST_CHECK_EQUAL(2, dependencyGroup->GetDependenciesCount());
			}
			// The 3 dependencies are depCA, depCB, and the current one from the loop.
			BOOST_CHECK_EQUAL(3, childHostC->GetDependencies().size());
		}
		BOOST_CHECK_EQUAL(isAnExactDuplicate ? 2 : 3, DependencyGroup::GetRegistrySize());
		childHostC->RemoveDependency(dependency);
	}

	childHostC->RemoveDependency(depCA);
	childHostD->RemoveDependency(depDA);
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 2);
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	childHostC->RemoveDependency(depCB);
	childHostD->RemoveDependency(depDB);
	AssertCheckableRedundancyGroup(childHostC, 0, 0, 0);
	AssertCheckableRedundancyGroup(childHostD, 0, 0, 0);
	BOOST_CHECK_EQUAL(0, DependencyGroup::GetRegistrySize());
}

BOOST_AUTO_TEST_CASE(simple_redundancy_group_registration_unregistration)
{
	Checkable::Ptr childHostC(CreateHost("childC"));

	Dependency::Ptr depCA(CreateDependency(CreateHost("A"), childHostC, "depCA"));
	RegisterDependency(depCA, "redundant");
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 1);
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depCB(CreateDependency(CreateHost("B"), childHostC, "depCB"));
	RegisterDependency(depCB, "redundant");
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 2);
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	Checkable::Ptr childHostD(CreateHost("childD"));
	Dependency::Ptr depDA (CreateDependency(depCA->GetParent(), childHostD, "depDA"));
	RegisterDependency(depDA, "redundant");
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 1);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depDB(CreateDependency(depCB->GetParent(), childHostD, "depDB"));
	RegisterDependency(depDB, "redundant");
	// Still 1 redundancy group, but there should be 4 dependencies now, i.e. 2 for each child Checkable.
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
	AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	childHostC->RemoveDependency(depCA);
	// After unregistering depCA, childHostC should have a new redundancy group with only depCB as dependency, and...
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 1);
	// ...childHostD should still have the same redundancy group as before but also with only two dependencies.
	AssertCheckableRedundancyGroup(childHostD, 2, 1, 2);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	childHostD->RemoveDependency(depDA);
	// Nothing should have changed for childHostC, but childHostD should now have a fewer group dependency, i.e.
	// both child hosts should have the same redundancy group with only depCB and depDB as dependency.
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 2);
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	RegisterDependency(depDA, depDA->GetRedundancyGroup());
	childHostD->RemoveDependency(depDB);
	// Nothing should have changed for childHostC, but both should now have a separate group with only depCB and depDA as dependency.
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 1);
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 1);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	childHostC->RemoveDependency(depCB);
	childHostD->RemoveDependency(depDA);
	AssertCheckableRedundancyGroup(childHostC, 0, 0, 0);
	AssertCheckableRedundancyGroup(childHostD, 0, 0, 0);
	BOOST_CHECK_EQUAL(0, DependencyGroup::GetRegistrySize());
}

BOOST_AUTO_TEST_CASE(mixed_redundancy_group_registration_unregsitration)
{
	Checkable::Ptr childHostC(CreateHost("childC"));
	Dependency::Ptr depCA(CreateDependency(CreateHost("A"), childHostC, "depCA"));
	RegisterDependency(depCA, "redundant");
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 1);
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	Checkable::Ptr childHostD(CreateHost("childD"));
	Dependency::Ptr depDA(CreateDependency(depCA->GetParent(), childHostD, "depDA"));
	RegisterDependency(depDA, "redundant");
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depCB(CreateDependency(CreateHost("B"), childHostC, "depCB"));
	RegisterDependency(depCB, "redundant");
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 2);
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 1);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depDB(CreateDependency(depCB->GetParent(), childHostD, "depDB"));
	RegisterDependency(depDB, "redundant");
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
	AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	Checkable::Ptr childHostE(CreateHost("childE"));
	Dependency::Ptr depEA(CreateDependency(depCA->GetParent(), childHostE, "depEA"));
	RegisterDependency(depEA, "redundant");
	AssertCheckableRedundancyGroup(childHostE, 1, 1, 1);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depEB(CreateDependency(depCB->GetParent(), childHostE, "depEB"));
	RegisterDependency(depEB, "redundant");
	// All 3 hosts share the same group, and each host has 2 dependencies, thus 6 dependencies in total.
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 6);
	AssertCheckableRedundancyGroup(childHostD, 2, 1, 6);
	AssertCheckableRedundancyGroup(childHostE, 2, 1, 6);
	auto childHostCGroups(ExtractGroups(childHostC));
	BOOST_TEST((childHostCGroups == ExtractGroups(childHostD) && childHostCGroups == ExtractGroups(childHostE)));
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	Dependency::Ptr depEZ(CreateDependency(CreateHost("Z"), childHostE, "depEZ"));
	RegisterDependency(depEZ, "redundant");
	// Child host E should have a new redundancy group with 3 dependencies and the other two should still share the same group.
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
	AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	AssertCheckableRedundancyGroup(childHostE, 3, 1, 3);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	childHostE->RemoveDependency(depEA);
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
	AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
	BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
	AssertCheckableRedundancyGroup(childHostE, 2, 1, 2);
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	RegisterDependency(depEA, depEA->GetRedundancyGroup()); // Re-register depEA and instead...
	childHostE->RemoveDependency(depEZ); // ...unregister depEZ and check if all the hosts share the same group again.
	// All 3 hosts share the same group again, and each host has 2 dependencies, thus 6 dependencies in total.
	AssertCheckableRedundancyGroup(childHostC, 2, 1, 6);
	AssertCheckableRedundancyGroup(childHostD, 2, 1, 6);
	AssertCheckableRedundancyGroup(childHostE, 2, 1, 6);
	childHostCGroups = ExtractGroups(childHostC);
	BOOST_TEST((childHostCGroups == ExtractGroups(childHostD) && childHostCGroups == ExtractGroups(childHostE)));
	BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());

	childHostC->RemoveDependency(depCA);
	childHostD->RemoveDependency(depDB);
	childHostE->RemoveDependency(depEB);
	// Child host C has now a separate group with only depCB as dependency, and child hosts D and E share the same group.
	AssertCheckableRedundancyGroup(childHostC, 1, 1, 1);
	AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
	AssertCheckableRedundancyGroup(childHostE, 1, 1, 2);
	BOOST_TEST(ExtractGroups(childHostD) == ExtractGroups(childHostE), boost::test_tools::per_element());
	BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());

	childHostC->RemoveDependency(depCB);
	childHostD->RemoveDependency(depDA);
	childHostE->RemoveDependency(depEA);
	AssertCheckableRedundancyGroup(childHostC, 0, 0, 0);
	AssertCheckableRedundancyGroup(childHostD, 0, 0, 0);
	AssertCheckableRedundancyGroup(childHostE, 0, 0, 0);
	BOOST_CHECK_EQUAL(0, DependencyGroup::GetRegistrySize());
}

BOOST_AUTO_TEST_SUITE_END()