1#define BOOST_TEST_MODULE monitor_loop
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;
63 mock_get_space = [ i = 0, num_loops ](
const bfs::path&
p, boost::system::error_code& ec)
mutable -> bfs::space_info {
64 ec = boost::system::errc::make_error_code(errc::success);
67 rc.capacity = 1000000;
69 if ( i < num_loops + 1 ) {
70 rc.available = 300000;
72 rc.available = 100000;
90 auto start = std::chrono::system_clock::now();
92 auto monitor_thread = std::thread( [
this] {
97 monitor_thread.join();
99 auto end = std::chrono::system_clock::now();
100 std::chrono::duration<double> test_duration = end - start;
106 bool finished_in_time = (test_duration >= std::chrono::duration<double>((num_loops - 1) * interval));
108 return finished_in_time;
112 std::function<bfs::space_info(
const bfs::path&
p, boost::system::error_code& ec)>
mock_get_space;
118BOOST_AUTO_TEST_SUITE(monitor_loop_tests)
121 BOOST_TEST( test_loop_common(0, 1) );
126 BOOST_TEST( test_loop_common(1, 1) );
131 BOOST_TEST( test_loop_common(2, 1) );
136 BOOST_TEST( test_loop_common(10, 1) );
141 BOOST_TEST( test_loop_common(1, 5) );
146 BOOST_TEST( test_loop_common(2, 5) );
151 BOOST_TEST( test_loop_common(10, 5) );
156 BOOST_TEST( test_loop_common(120, 1) );
159BOOST_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 space_monitor_loop()
void set_shutdown_on_exceeded(bool new_shutdown_on_exceeded)
void set_sleep_time(uint32_t sleep_time)
bfs::space_info get_space(const bfs::path &p, boost::system::error_code &ec) const
mock_space_provider(space_handler_fixture &fixture)
int get_stat(const char *path, struct stat *buf) const
space_handler_fixture & fixture
std::function< bfs::space_info(const bfs::path &p, boost::system::error_code &ec)> mock_get_space
void set_threshold(uint32_t threshold, uint32_t warning_threshold)
bool test_loop_common(int num_loops, int interval)
void set_sleep_time(uint32_t sleep_time)
void set_shutdown_on_exceeded(bool shutdown_on_exceeded)
boost::asio::io_context ctx
void add_file_system(const bfs::path &path_name)
std::function< int(const char *path, struct stat *buf)> mock_get_stat
void space_monitor_loop()
file_space_handler_t space_handler
bool is_threshold_exceeded()
BOOST_FIXTURE_TEST_CASE(zero_loop, space_handler_fixture)