added variable for threshold for switching from "all congested" --> "connection failed"
[pingcheck] / test / test_hoststatus.cpp
CommitLineData
6f19218c
GMF
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
20
a72f06b6 21#define BOOST_TEST_MAIN
6f19218c 22#define BOOST_TEST_DYN_LINK
6f19218c
GMF
23
24#include <streambuf>
25
26#include <boost/asio.hpp>
27#include <boost/test/unit_test.hpp>
28
72e54d1c 29#include "mock_linkstatus.h"
6f19218c 30
6c14bbee 31#include "host/hoststatus.h"
96c4e7a4 32#include "host/pingstatus.h"
6f19218c 33
6c14bbee 34BOOST_AUTO_TEST_SUITE( TestHostStatus )
6f19218c
GMF
35
36BOOST_AUTO_TEST_CASE( fail_percentage_10 )
37{
38 int ping_fail_percentage_limit = 10;
a7b15639 39 int ping_congestion_percentage_limit = 75;
941b5e25 40 int congest_caused_by_fail_percentage_limit = 90;
a7b15639
CH
41 int ping_congestion_duration_thresh = 5;
42 int n_parallel_pings = 1;
6f19218c
GMF
43 int resolved_ip_count = 10;
44
72e54d1c 45 LinkStatusItem link_status( new LinkStatus );
a7b15639
CH
46 HostStatus host_status( "localhost",
47 ping_fail_percentage_limit,
48 ping_congestion_percentage_limit,
941b5e25 49 congest_caused_by_fail_percentage_limit,
a7b15639
CH
50 ping_congestion_duration_thresh,
51 n_parallel_pings,
91aa83f9 52 link_status );
6f19218c
GMF
53 host_status.set_resolved_ip_count( resolved_ip_count );
54
96c4e7a4 55 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
56 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
57
96c4e7a4 58 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
59 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
60
96c4e7a4 61 host_status.update_ping_statistics( PingStatus_FailureOther, 1);
6f19218c
GMF
62 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
63
96c4e7a4 64 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
65 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
66
96c4e7a4 67 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
68 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
69
96c4e7a4 70 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
71 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
72
96c4e7a4 73 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
74 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
75
96c4e7a4 76 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
77 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
78
96c4e7a4 79 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
80 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
81
96c4e7a4 82 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
83 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
84}
85
86BOOST_AUTO_TEST_CASE( fail_percentage_50 )
87{
88 int ping_fail_percentage_limit = 50;
a7b15639 89 int ping_congestion_percentage_limit = 75;
941b5e25 90 int congest_caused_by_fail_percentage_limit = 90;
a7b15639
CH
91 int ping_congestion_duration_thresh = 5;
92 int n_parallel_pings = 1;
6f19218c
GMF
93 int resolved_ip_count = 10;
94
72e54d1c 95 LinkStatusItem link_status( new LinkStatus );
a7b15639
CH
96 HostStatus host_status( "localhost",
97 ping_fail_percentage_limit,
98 ping_congestion_percentage_limit,
941b5e25 99 congest_caused_by_fail_percentage_limit,
a7b15639
CH
100 ping_congestion_duration_thresh,
101 n_parallel_pings,
91aa83f9 102 link_status );
6f19218c
GMF
103 host_status.set_resolved_ip_count( resolved_ip_count );
104
96c4e7a4 105 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
106 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
107
96c4e7a4 108 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
109 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
110
96c4e7a4 111 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
112 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
113
96c4e7a4 114 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
115 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
116
96c4e7a4 117 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
118 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
119
96c4e7a4 120 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
121 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
122
96c4e7a4 123 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
124 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
125
96c4e7a4 126 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
127 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
128
96c4e7a4 129 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
130 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
131
96c4e7a4 132 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
133 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
134}
135
136BOOST_AUTO_TEST_CASE( fail_percentage_80 )
137{
138 int ping_fail_percentage_limit = 80;
a7b15639 139 int ping_congestion_percentage_limit = 75;
941b5e25 140 int congest_caused_by_fail_percentage_limit = 90;
a7b15639
CH
141 int ping_congestion_duration_thresh = 5;
142 int n_parallel_pings = 1;
6f19218c
GMF
143 int resolved_ip_count = 10;
144
72e54d1c 145 LinkStatusItem link_status( new LinkStatus );
a7b15639
CH
146 HostStatus host_status( "localhost",
147 ping_fail_percentage_limit,
148 ping_congestion_percentage_limit,
941b5e25 149 congest_caused_by_fail_percentage_limit,
a7b15639
CH
150 ping_congestion_duration_thresh,
151 n_parallel_pings,
91aa83f9 152 link_status );
6f19218c
GMF
153 host_status.set_resolved_ip_count( resolved_ip_count );
154
96c4e7a4 155 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
156 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
157
96c4e7a4 158 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
159 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
160
96c4e7a4 161 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
162 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
163
96c4e7a4 164 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
165 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
166
96c4e7a4 167 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
168 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
169
96c4e7a4 170 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
171 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
172
96c4e7a4 173 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
174 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
175
96c4e7a4 176 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
177 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
178
96c4e7a4 179 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
180 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
181
96c4e7a4 182 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
183 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
184}
185
186BOOST_AUTO_TEST_SUITE_END()