1#define BOOST_TEST_MODULE threshold 
    2#include <boost/test/included/unit_test.hpp> 
   10using namespace boost::system;
 
   22      bfs::space_info 
get_space(
const bfs::path& 
p, boost::system::error_code& ec)
 const {
 
 
 
   29   boost::asio::io_context 
ctx;
 
   55      mock_get_space = [available]( 
const bfs::path& 
p, boost::system::error_code& ec) 
mutable -> bfs::space_info {
 
   56         ec = boost::system::errc::make_error_code(errc::success);
 
   59         rc.capacity  = 1000000;
 
   60         rc.available = available[
p];
 
   75      for (
auto i = 0; i < available.size(); i++) {
 
 
   83   std::function<bfs::space_info(
const bfs::path& 
p, boost::system::error_code& ec)> 
mock_get_space;
 
 
   89BOOST_AUTO_TEST_SUITE(threshol_tests)
 
   92      std::map<bfs::path, uintmax_t> availables {{
"/test0", 200000}};
 
   93      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
   95      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  100      std::map<bfs::path, uintmax_t> availables {{
"/test0", 199999}};
 
  101      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  103      BOOST_TEST( test_threshold_common(availables, devs) );
 
 
  108      std::map<bfs::path, uintmax_t> availables {{
"/test0", 199000}};
 
  109      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  111      BOOST_TEST( test_threshold_common(availables, devs) );
 
 
  116      std::map<bfs::path, uintmax_t> availables {{
"/test0", 249999}};
 
  117      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  119      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  124      std::map<bfs::path, uintmax_t> availables {{
"/test0", 250001}};
 
  125      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  127      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  132      std::map<bfs::path, uintmax_t> availables {{
"/test0", 200001}};
 
  133      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  135      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  140      std::map<bfs::path, uintmax_t> availables {{
"/test0", 200500}};
 
  141      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  143      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  148      std::map<bfs::path, uintmax_t> availables {{
"/test0", 199999},
 
  150      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  153      BOOST_TEST( test_threshold_common(availables, devs) );
 
 
  158      std::map<bfs::path, uintmax_t> availables {{
"/test0", 300000},
 
  160      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  163      BOOST_TEST( test_threshold_common(availables, devs) );
 
 
  168      std::map<bfs::path, uintmax_t> availables {{
"/test0", 300000},
 
  170      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  173      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  178      std::map<bfs::path, uintmax_t> availables {{
"/test0", 150000},
 
  180      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  183      BOOST_TEST( test_threshold_common(availables, devs) );
 
 
  188      std::map<bfs::path, uintmax_t> availables {{
"/test0", 300000},
 
  191      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  195      BOOST_TEST( test_threshold_common(availables, devs) );
 
 
  200      std::map<bfs::path, uintmax_t> availables {{
"/test0", 100000},
 
  203      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  207      BOOST_TEST( test_threshold_common(availables, devs) );
 
 
  212      std::map<bfs::path, uintmax_t> availables {{
"/test0", 300000},
 
  215      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  219      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  224      std::map<bfs::path, uintmax_t> availables {{
"/test0", 800000},
 
  227      std::map<bfs::path, int>       devs       {{
"/test0", 0},
 
  231      BOOST_TEST( !test_threshold_common(availables, devs) );
 
 
  236      std::map<bfs::path, uintmax_t> availables {{
"/test0", 150000}};
 
  237      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  239      BOOST_REQUIRE_THROW(test_threshold_common(availables, devs, 80), chain::plugin_config_exception);
 
 
  244      std::map<bfs::path, uintmax_t> availables {{
"/test0", 150000}};
 
  245      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  247      BOOST_REQUIRE_THROW( test_threshold_common(availables, devs, 85), chain::plugin_config_exception );
 
 
  252      std::map<bfs::path, uintmax_t> availables {{
"/test0", 200000}};
 
  253      std::map<bfs::path, int>       devs       {{
"/test0", 0}};
 
  255      BOOST_TEST( !test_threshold_common(availables, devs, 70) );
 
 
  260      mock_get_space = [ i = 0 ]( 
const bfs::path& 
p, boost::system::error_code& ec) 
mutable -> bfs::space_info {
 
  262            ec = boost::system::errc::make_error_code(errc::no_such_file_or_directory);
 
  264            ec = boost::system::errc::make_error_code(errc::success);
 
  268         rc.capacity  = 1000000;
 
  269         rc.available = 200500;
 
  276      mock_get_stat = []( 
const char *
path, 
struct stat *
buf ) -> 
int {
 
  281      set_threshold(80, 75);
 
  282      add_file_system(
"/test");
 
  284      auto expected_response = 
false;
 
  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();
 
  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);
 
 
  301BOOST_AUTO_TEST_SUITE_END()
 
wraps boost::filesystem::path to provide platform independent path manipulation.
 
bool is_threshold_exceeded()
 
void set_threshold(uint32_t new_threshold, uint32_t new_warning_threshold)
 
void add_file_system(const bfs::path &path_name)
 
void set_shutdown_on_exceeded(bool new_shutdown_on_exceeded)
 
Immutable except for fc::from_variant.
 
threshold_fixture & fixture
 
int get_stat(const char *path, struct stat *buf) const
 
mock_space_provider(threshold_fixture &fixture)
 
bfs::space_info get_space(const bfs::path &p, boost::system::error_code &ec) const
 
void set_shutdown_on_exceeded(bool shutdown_on_exceeded)
 
bool test_threshold_common(std::map< bfs::path, uintmax_t > &available, std::map< bfs::path, int > &dev, uint32_t warning_threshold=75)
 
void set_threshold(uint32_t threshold, uint32_t warning_threshold)
 
void add_file_system(const bfs::path &path_name)
 
std::function< int(const char *path, struct stat *buf)> mock_get_stat
 
file_space_handler_t space_handler
 
bool is_threshold_exceeded()
 
std::function< bfs::space_info(const bfs::path &p, boost::system::error_code &ec)> mock_get_space
 
boost::asio::io_context ctx
 
BOOST_FIXTURE_TEST_CASE(equal_to_threshold, threshold_fixture)