Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_resmon_plugin.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE test_resmom_plugin
2#include <boost/test/included/unit_test.hpp>
3
5
7
8#include <thread>
9
10using namespace sysio;
11using namespace boost::system;
12
13namespace bfs = boost::filesystem;
14
15// For program options
16namespace bpo = boost::program_options;
17using bpo::options_description;
18using bpo::variables_map;
19
22 options_description dummy;
24 }
25
26 void initialize(const std::vector<std::string>& args){
27 // We only have at most 3 arguments. OK to hardcodied in test
28 // programs.
29 const char* argv[10];
30 SYS_ASSERT(args.size() < 10, chain::plugin_exception, "number of arguments (${size}) must be less than 10", ("size", args.size()));
31
32 // argv[0] is program name, no need to fill in
33 for (size_t i=0; i<args.size(); ++i) {
34 argv[i+1] = args[i].c_str();
35 }
36
37 bpo::variables_map options;
38 bpo::store(bpo::parse_command_line(args.size()+1, argv, _cfg), options);
39 bpo::notify(options);
40
41 _my.plugin_initialize(options);
42 }
43
44 void set_options(const std::vector<std::string>& arg) {
46 initialize(arg);
47 }
48
49 void plugin_startup(const std::vector<bfs::path>& dirs, int runTimeSecs=3) {
50 set_options({"--resource-monitor-interval-seconds=1"});
51
52 for (auto& dir: dirs) {
54 }
55
57 std::this_thread::sleep_for( std::chrono::milliseconds(runTimeSecs*1000) );
59 }
60
62 options_description _cfg;
63};
64
65BOOST_AUTO_TEST_SUITE(resmon_plugin_tests)
67 {
68 BOOST_REQUIRE_THROW(set_options({"--resource-monitor-interval-seconds=301"}), chain::plugin_config_exception);
69 }
70
72 {
73 BOOST_REQUIRE_THROW(set_options({"--resource-monitor-interval-seconds=0"}), chain::plugin_config_exception);
74 }
75
77 {
78 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-interval-seconds=1"}));
79 }
80
82 {
83 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-interval-seconds=150"}));
84 }
85
87 {
88 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-interval-seconds=300"}));
89 }
90
92 {
93 BOOST_REQUIRE_THROW(set_options({"--resource-monitor-space-threshold=100"}), chain::plugin_config_exception);
94 }
95
97 {
98 BOOST_REQUIRE_THROW(set_options({"--resource-monitor-space-threshold=5"}), chain::plugin_config_exception);
99 }
100
102 {
103 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-space-threshold=6"}));
104 }
105
107 {
108 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-space-threshold=60"}));
109 }
110
112 {
113 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-space-threshold=99"}));
114 }
115
117 {
118 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-not-shutdown-on-threshold-exceeded"}));
119 }
120
122 {
123 BOOST_REQUIRE_NO_THROW( plugin_startup({"/tmp"}));
124 }
125
127 {
128 BOOST_REQUIRE_NO_THROW( plugin_startup({"/tmp", "/tmp"}));
129 }
130
132 {
133 // Under "/" are multiple file systems
134 BOOST_REQUIRE_NO_THROW( plugin_startup({"/", "/tmp"}));
135 }
136
138 {
139 // "hsdfgd983" a random file and not existing
140 BOOST_REQUIRE_THROW( plugin_startup({"/tmp", "hsdfgd983"}), chain::plugin_config_exception);
141 }
142
144 {
145 BOOST_REQUIRE_NO_THROW( plugin_startup({"/tmp"}, 120));
146 }
147
149 {
150 BOOST_REQUIRE_THROW(set_options({"--resource-monitor-warning-interval=451"}), chain::plugin_config_exception);
151 }
152
153 BOOST_FIXTURE_TEST_CASE(warningIntervalTooSmall, resmon_fixture)
154 {
155 BOOST_REQUIRE_THROW(set_options({"--resource-monitor-warning-interval=0"}), chain::plugin_config_exception);
156 }
157
158 BOOST_FIXTURE_TEST_CASE(warningIntervalLowBound, resmon_fixture)
159 {
160 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-warning-interval=1"}));
161 }
162
164 {
165 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-warning-interval=225"}));
166 }
167
168 BOOST_FIXTURE_TEST_CASE(warningIntervalHighBound, resmon_fixture)
169 {
170 BOOST_REQUIRE_NO_THROW(set_options({"--resource-monitor-warning-interval=450"}));
171 }
172
173BOOST_AUTO_TEST_SUITE_END()
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
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)
char ** argv
resource_monitor_plugin _my
options_description _cfg
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)
BOOST_FIXTURE_TEST_CASE(intervalTooBig, resmon_fixture)