1#define BOOST_TEST_MODULE test_resmom_plugin
2#include <boost/test/included/unit_test.hpp>
11using namespace boost::system;
16namespace bpo = boost::program_options;
17using bpo::options_description;
18using bpo::variables_map;
22 options_description dummy;
30 SYS_ASSERT(args.size() < 10, chain::plugin_exception,
"number of arguments (${size}) must be less than 10", (
"size", args.size()));
33 for (
size_t i=0; i<args.size(); ++i) {
34 argv[i+1] = args[i].c_str();
37 bpo::variables_map options;
38 bpo::store(bpo::parse_command_line(args.size()+1,
argv,
_cfg), options);
50 set_options({
"--resource-monitor-interval-seconds=1"});
52 for (
auto& dir: dirs) {
57 std::this_thread::sleep_for( std::chrono::milliseconds(runTimeSecs*1000) );
65BOOST_AUTO_TEST_SUITE(resmon_plugin_tests)
68 BOOST_REQUIRE_THROW(set_options({
"--resource-monitor-interval-seconds=301"}), chain::plugin_config_exception);
73 BOOST_REQUIRE_THROW(set_options({
"--resource-monitor-interval-seconds=0"}), chain::plugin_config_exception);
78 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-interval-seconds=1"}));
83 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-interval-seconds=150"}));
88 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-interval-seconds=300"}));
93 BOOST_REQUIRE_THROW(set_options({
"--resource-monitor-space-threshold=100"}), chain::plugin_config_exception);
98 BOOST_REQUIRE_THROW(set_options({
"--resource-monitor-space-threshold=5"}), chain::plugin_config_exception);
103 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-space-threshold=6"}));
108 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-space-threshold=60"}));
113 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-space-threshold=99"}));
118 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-not-shutdown-on-threshold-exceeded"}));
123 BOOST_REQUIRE_NO_THROW( plugin_startup({
"/tmp"}));
128 BOOST_REQUIRE_NO_THROW( plugin_startup({
"/tmp",
"/tmp"}));
134 BOOST_REQUIRE_NO_THROW( plugin_startup({
"/",
"/tmp"}));
140 BOOST_REQUIRE_THROW( plugin_startup({
"/tmp",
"hsdfgd983"}), chain::plugin_config_exception);
145 BOOST_REQUIRE_NO_THROW( plugin_startup({
"/tmp"}, 120));
150 BOOST_REQUIRE_THROW(set_options({
"--resource-monitor-warning-interval=451"}), chain::plugin_config_exception);
155 BOOST_REQUIRE_THROW(set_options({
"--resource-monitor-warning-interval=0"}), chain::plugin_config_exception);
160 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-warning-interval=1"}));
165 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-warning-interval=225"}));
170 BOOST_REQUIRE_NO_THROW(set_options({
"--resource-monitor-warning-interval=450"}));
173BOOST_AUTO_TEST_SUITE_END()
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
virtual void set_program_options(options_description &, options_description &cfg) override
void monitor_directory(const bfs::path &path)
void plugin_initialize(const variables_map &options)
resource_monitor_plugin _my
void initialize(const std::vector< std::string > &args)
void set_options(const std::vector< std::string > &arg)
void plugin_startup(const std::vector< bfs::path > &dirs, int runTimeSecs=3)
void set_program_options()
BOOST_FIXTURE_TEST_CASE(intervalTooBig, resmon_fixture)