Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_threshold.cpp File Reference
#include <boost/test/included/unit_test.hpp>
#include <fc/variant_object.hpp>
#include <sysio/resource_monitor_plugin/file_space_handler.hpp>
Include dependency graph for test_threshold.cpp:

Go to the source code of this file.

Classes

struct  threshold_fixture
 
struct  threshold_fixture::mock_space_provider
 

Macros

#define BOOST_TEST_MODULE   threshold
 

Functions

 BOOST_FIXTURE_TEST_CASE (equal_to_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (above_threshold_1_byte, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (above_threshold_1000_byte, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (within_warning, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (not_yet_warning, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (below_threshold_1_byte, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (below_threshold_500_byte, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (first_file_system_over_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (second_file_system_over_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (no_file_system_over_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (both_file_systems_over_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (one_of_three_over_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (one_of_three_over_threshold_dup, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (none_of_three_over_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (none_of_three_over_threshold_dup, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (warning_threshold_equal_to_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (warning_threshold_greater_than_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (warning_threshold_less_than_threshold, threshold_fixture)
 
 BOOST_FIXTURE_TEST_CASE (get_space_failure_in_middle, threshold_fixture)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   threshold

Definition at line 1 of file test_threshold.cpp.

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/19]

BOOST_FIXTURE_TEST_CASE ( above_threshold_1000_byte ,
threshold_fixture  )

Definition at line 106 of file test_threshold.cpp.

107 {
108 std::map<bfs::path, uintmax_t> availables {{"/test0", 199000}};
109 std::map<bfs::path, int> devs {{"/test0", 0}};
110
111 BOOST_TEST( test_threshold_common(availables, devs) );
112 }

◆ BOOST_FIXTURE_TEST_CASE() [2/19]

BOOST_FIXTURE_TEST_CASE ( above_threshold_1_byte ,
threshold_fixture  )

Definition at line 98 of file test_threshold.cpp.

99 {
100 std::map<bfs::path, uintmax_t> availables {{"/test0", 199999}};
101 std::map<bfs::path, int> devs {{"/test0", 0}};
102
103 BOOST_TEST( test_threshold_common(availables, devs) );
104 }

◆ BOOST_FIXTURE_TEST_CASE() [3/19]

BOOST_FIXTURE_TEST_CASE ( below_threshold_1_byte ,
threshold_fixture  )

Definition at line 130 of file test_threshold.cpp.

131 {
132 std::map<bfs::path, uintmax_t> availables {{"/test0", 200001}};
133 std::map<bfs::path, int> devs {{"/test0", 0}};
134
135 BOOST_TEST( !test_threshold_common(availables, devs) );
136 }

◆ BOOST_FIXTURE_TEST_CASE() [4/19]

BOOST_FIXTURE_TEST_CASE ( below_threshold_500_byte ,
threshold_fixture  )

Definition at line 138 of file test_threshold.cpp.

139 {
140 std::map<bfs::path, uintmax_t> availables {{"/test0", 200500}};
141 std::map<bfs::path, int> devs {{"/test0", 0}};
142
143 BOOST_TEST( !test_threshold_common(availables, devs) );
144 }

◆ BOOST_FIXTURE_TEST_CASE() [5/19]

BOOST_FIXTURE_TEST_CASE ( both_file_systems_over_threshold ,
threshold_fixture  )

Definition at line 176 of file test_threshold.cpp.

177 {
178 std::map<bfs::path, uintmax_t> availables {{"/test0", 150000},
179 {"/test1", 100000}};
180 std::map<bfs::path, int> devs {{"/test0", 0},
181 {"/test1", 1}};
182
183 BOOST_TEST( test_threshold_common(availables, devs) );
184 }

◆ BOOST_FIXTURE_TEST_CASE() [6/19]

BOOST_FIXTURE_TEST_CASE ( equal_to_threshold ,
threshold_fixture  )

Definition at line 90 of file test_threshold.cpp.

91 {
92 std::map<bfs::path, uintmax_t> availables {{"/test0", 200000}};
93 std::map<bfs::path, int> devs {{"/test0", 0}};
94
95 BOOST_TEST( !test_threshold_common(availables, devs) );
96 }

◆ BOOST_FIXTURE_TEST_CASE() [7/19]

BOOST_FIXTURE_TEST_CASE ( first_file_system_over_threshold ,
threshold_fixture  )

Definition at line 146 of file test_threshold.cpp.

147 {
148 std::map<bfs::path, uintmax_t> availables {{"/test0", 199999},
149 {"/test1", 200500}};
150 std::map<bfs::path, int> devs {{"/test0", 0},
151 {"/test1", 1}};
152
153 BOOST_TEST( test_threshold_common(availables, devs) );
154 }

◆ BOOST_FIXTURE_TEST_CASE() [8/19]

BOOST_FIXTURE_TEST_CASE ( get_space_failure_in_middle ,
threshold_fixture  )

Definition at line 258 of file test_threshold.cpp.

259 {
260 mock_get_space = [ i = 0 ]( const bfs::path& p, boost::system::error_code& ec) mutable -> bfs::space_info {
261 if ( i == 3 ) {
262 ec = boost::system::errc::make_error_code(errc::no_such_file_or_directory);
263 } else {
264 ec = boost::system::errc::make_error_code(errc::success);
265 }
266
267 bfs::space_info rc;
268 rc.capacity = 1000000;
269 rc.available = 200500;
270
271 i++;
272
273 return rc;
274 };
275
276 mock_get_stat = []( const char *path, struct stat *buf ) -> int {
277 buf->st_dev = 0;
278 return 0;
279 };
280
281 set_threshold(80, 75);
282 add_file_system("/test");
283
284 auto expected_response = false;
285
286 auto actual_response_0 = is_threshold_exceeded();
287 auto actual_response_1 = is_threshold_exceeded();
288 auto actual_response_2 = is_threshold_exceeded();
289 auto actual_response_3 = is_threshold_exceeded();
290 auto actual_response_4 = is_threshold_exceeded();
291 auto actual_response_5 = is_threshold_exceeded();
292
293 BOOST_TEST(expected_response == actual_response_0);
294 BOOST_TEST(expected_response == actual_response_1);
295 BOOST_TEST(expected_response == actual_response_2);
296 BOOST_TEST(expected_response == actual_response_3);
297 BOOST_TEST(expected_response == actual_response_4);
298 BOOST_TEST(expected_response == actual_response_5);
299 }
const mie::Vuint & p
Definition bn.cpp:27
wraps boost::filesystem::path to provide platform independent path manipulation.
uint8_t buf[2048]
yh_rc rc

◆ BOOST_FIXTURE_TEST_CASE() [9/19]

BOOST_FIXTURE_TEST_CASE ( no_file_system_over_threshold ,
threshold_fixture  )

Definition at line 166 of file test_threshold.cpp.

167 {
168 std::map<bfs::path, uintmax_t> availables {{"/test0", 300000},
169 {"/test1", 200000}};
170 std::map<bfs::path, int> devs {{"/test0", 0},
171 {"/test1", 1}};
172
173 BOOST_TEST( !test_threshold_common(availables, devs) );
174 }

◆ BOOST_FIXTURE_TEST_CASE() [10/19]

BOOST_FIXTURE_TEST_CASE ( none_of_three_over_threshold ,
threshold_fixture  )

Definition at line 210 of file test_threshold.cpp.

211 {
212 std::map<bfs::path, uintmax_t> availables {{"/test0", 300000},
213 {"/test1", 200000},
214 {"/test2", 250000}};
215 std::map<bfs::path, int> devs {{"/test0", 0},
216 {"/test1", 1},
217 {"/test2", 2}};
218
219 BOOST_TEST( !test_threshold_common(availables, devs) );
220 }

◆ BOOST_FIXTURE_TEST_CASE() [11/19]

BOOST_FIXTURE_TEST_CASE ( none_of_three_over_threshold_dup ,
threshold_fixture  )

Definition at line 222 of file test_threshold.cpp.

223 {
224 std::map<bfs::path, uintmax_t> availables {{"/test0", 800000},
225 {"/test1", 550000},
226 {"/test2", 550000}};
227 std::map<bfs::path, int> devs {{"/test0", 0},
228 {"/test1", 1}, // dup
229 {"/test2", 1}}; // dup
230
231 BOOST_TEST( !test_threshold_common(availables, devs) );
232 }

◆ BOOST_FIXTURE_TEST_CASE() [12/19]

BOOST_FIXTURE_TEST_CASE ( not_yet_warning ,
threshold_fixture  )

Definition at line 122 of file test_threshold.cpp.

123 {
124 std::map<bfs::path, uintmax_t> availables {{"/test0", 250001}};
125 std::map<bfs::path, int> devs {{"/test0", 0}};
126
127 BOOST_TEST( !test_threshold_common(availables, devs) );
128 }

◆ BOOST_FIXTURE_TEST_CASE() [13/19]

BOOST_FIXTURE_TEST_CASE ( one_of_three_over_threshold ,
threshold_fixture  )

Definition at line 186 of file test_threshold.cpp.

187 {
188 std::map<bfs::path, uintmax_t> availables {{"/test0", 300000},
189 {"/test1", 199999},
190 {"/test2", 250000}};
191 std::map<bfs::path, int> devs {{"/test0", 0},
192 {"/test1", 1},
193 {"/test2", 2}};
194
195 BOOST_TEST( test_threshold_common(availables, devs) );
196 }

◆ BOOST_FIXTURE_TEST_CASE() [14/19]

BOOST_FIXTURE_TEST_CASE ( one_of_three_over_threshold_dup ,
threshold_fixture  )

Definition at line 198 of file test_threshold.cpp.

199 {
200 std::map<bfs::path, uintmax_t> availables {{"/test0", 100000},
201 {"/test1", 250000},
202 {"/test2", 250000}};
203 std::map<bfs::path, int> devs {{"/test0", 0},
204 {"/test1", 1}, // dup
205 {"/test2", 1}}; // dup
206
207 BOOST_TEST( test_threshold_common(availables, devs) );
208 }

◆ BOOST_FIXTURE_TEST_CASE() [15/19]

BOOST_FIXTURE_TEST_CASE ( second_file_system_over_threshold ,
threshold_fixture  )

Definition at line 156 of file test_threshold.cpp.

157 {
158 std::map<bfs::path, uintmax_t> availables {{"/test0", 300000},
159 {"/test1", 100000}};
160 std::map<bfs::path, int> devs {{"/test0", 0},
161 {"/test1", 1}};
162
163 BOOST_TEST( test_threshold_common(availables, devs) );
164 }

◆ BOOST_FIXTURE_TEST_CASE() [16/19]

BOOST_FIXTURE_TEST_CASE ( warning_threshold_equal_to_threshold ,
threshold_fixture  )

Definition at line 234 of file test_threshold.cpp.

235 {
236 std::map<bfs::path, uintmax_t> availables {{"/test0", 150000}};
237 std::map<bfs::path, int> devs {{"/test0", 0}};
238
239 BOOST_REQUIRE_THROW(test_threshold_common(availables, devs, 80), chain::plugin_config_exception);
240 }

◆ BOOST_FIXTURE_TEST_CASE() [17/19]

BOOST_FIXTURE_TEST_CASE ( warning_threshold_greater_than_threshold ,
threshold_fixture  )

Definition at line 242 of file test_threshold.cpp.

243 {
244 std::map<bfs::path, uintmax_t> availables {{"/test0", 150000}};
245 std::map<bfs::path, int> devs {{"/test0", 0}};
246
247 BOOST_REQUIRE_THROW( test_threshold_common(availables, devs, 85), chain::plugin_config_exception );
248 }

◆ BOOST_FIXTURE_TEST_CASE() [18/19]

BOOST_FIXTURE_TEST_CASE ( warning_threshold_less_than_threshold ,
threshold_fixture  )

Definition at line 250 of file test_threshold.cpp.

251 {
252 std::map<bfs::path, uintmax_t> availables {{"/test0", 200000}};
253 std::map<bfs::path, int> devs {{"/test0", 0}};
254
255 BOOST_TEST( !test_threshold_common(availables, devs, 70) );
256 }

◆ BOOST_FIXTURE_TEST_CASE() [19/19]

BOOST_FIXTURE_TEST_CASE ( within_warning ,
threshold_fixture  )

Definition at line 114 of file test_threshold.cpp.

115 {
116 std::map<bfs::path, uintmax_t> availables {{"/test0", 249999}};
117 std::map<bfs::path, int> devs {{"/test0", 0}};
118
119 BOOST_TEST( !test_threshold_common(availables, devs) );
120 }