Skip to content

Commit f0de2aa

Browse files
committed
Unconditionally allow processing CheckResults in tests
1 parent 4c08177 commit f0de2aa

File tree

5 files changed

+110
-94
lines changed

5 files changed

+110
-94
lines changed

lib/remote/crproducer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
using namespace icinga;
66

7+
bool UnitTestCRP::try_lock_shared() noexcept
8+
{
9+
return true;
10+
}
11+
12+
void UnitTestCRP::unlock_shared() noexcept
13+
{
14+
}
15+
716
bool CheckResultProducerComponent::try_lock_shared() noexcept
817
{
918
auto state (ModifyState(

lib/remote/crproducer.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class CheckResultProducer : virtual public Object
3535
virtual void unlock_shared() noexcept = 0;
3636
};
3737

38+
class UnitTestCRP : public CheckResultProducer
39+
{
40+
public:
41+
bool try_lock_shared() noexcept override;
42+
void unlock_shared() noexcept override;
43+
};
44+
3845
struct CrpComponentState
3946
{
4047
uint32_t InstanceIsActive = 0;

test/icinga-checkable-flapping.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(host_not_flapping)
7373
int i = 0;
7474
while (i++ < 10) {
7575
// For some reason, elusive to me, the first check is a state change
76-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
76+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
7777

7878
LogFlapping(host);
7979
LogHostStatus(host);
@@ -107,9 +107,9 @@ BOOST_AUTO_TEST_CASE(host_flapping)
107107
int i = 0;
108108
while (i++ < 25) {
109109
if (i % 2)
110-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
110+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
111111
else
112-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
112+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
113113

114114
LogFlapping(host);
115115
LogHostStatus(host);
@@ -144,18 +144,18 @@ BOOST_AUTO_TEST_CASE(host_flapping_recover)
144144
Utility::SetTime(0);
145145

146146
// A few warning
147-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
148-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
149-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
150-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
147+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
148+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
149+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
150+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
151151

152152
LogFlapping(host);
153153
LogHostStatus(host);
154154
for (int i = 0; i <= 7; i++) {
155155
if (i % 2)
156-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
156+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
157157
else
158-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
158+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
159159
}
160160

161161
LogFlapping(host);
@@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(host_flapping_recover)
171171
BOOST_CHECK(host->GetFlappingCurrent() > 25.0);
172172
BOOST_CHECK(host->IsFlapping());
173173

174-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
174+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
175175
LogFlapping(host);
176176
LogHostStatus(host);
177177
count++;
@@ -203,40 +203,40 @@ BOOST_AUTO_TEST_CASE(host_flapping_docs_example)
203203

204204
Utility::SetTime(0);
205205

206-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
207-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
208-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
209-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
210-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
211-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
212-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
213-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
214-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
215-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
216-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
217-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
218-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
219-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
220-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
221-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
222-
host->ProcessCheckResult(MakeCheckResult(ServiceOK));
223-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
224-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
225-
host->ProcessCheckResult(MakeCheckResult(ServiceWarning));
226-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
206+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
207+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
208+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
209+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
210+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
211+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
212+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
213+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
214+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
215+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
216+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
217+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
218+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
219+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
220+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
221+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
222+
host->ProcessCheckResult(MakeCheckResult(ServiceOK), new UnitTestCRP());
223+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
224+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
225+
host->ProcessCheckResult(MakeCheckResult(ServiceWarning), new UnitTestCRP());
226+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
227227

228228
LogFlapping(host);
229229
LogHostStatus(host);
230230
BOOST_CHECK(host->GetFlappingCurrent() == 39.1);
231231
BOOST_CHECK(host->IsFlapping());
232232

233-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
234-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
235-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
236-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
237-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
238-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
239-
host->ProcessCheckResult(MakeCheckResult(ServiceCritical));
233+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
234+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
235+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
236+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
237+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
238+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
239+
host->ProcessCheckResult(MakeCheckResult(ServiceCritical), new UnitTestCRP());
240240

241241
LogFlapping(host);
242242
LogHostStatus(host);

0 commit comments

Comments
 (0)