diff --git a/tests/logging_tests.cpp b/tests/logging_tests.cpp index ef66501af..217f75a94 100644 --- a/tests/logging_tests.cpp +++ b/tests/logging_tests.cpp @@ -36,22 +36,27 @@ BOOST_AUTO_TEST_CASE(log_reboot) fc::path prev_log_filename = ""; BOOST_TEST_MESSAGE("Starting Loop"); + int file_changed_count = 0; for(int i = 0; i < conf.rotation_limit.to_seconds(); i++) { fc::log_context ctx(fc::log_level::all, "my_file.cpp", i, "my_method()"); fc::log_message my_log_message( ctx, "${message}", {"message","This is a test"} ); + fc::time_point now = fc::time_point::now(); fa->log(my_log_message); - fc::time_point now = fc::time_point::now(); + fc::time_point new_now = fc::time_point::now(); int64_t interval_seconds = conf.rotation_interval.to_seconds(); int64_t file_number = now.sec_since_epoch() / interval_seconds; + bool file_changed = ( new_now.sec_since_epoch() / interval_seconds != file_number ); + if( file_changed ) + ++file_changed_count; fc::time_point_sec start_time = fc::time_point_sec( (uint32_t)(file_number * interval_seconds) ); std::string timestamp_string = start_time.to_non_delimited_iso_string(); fc::path link_filename = conf.filename; fc::path log_filename = link_filename.parent_path() / (link_filename.filename().string() + "." + timestamp_string); if (prev_log_filename != log_filename) { - if (i > conf.rotation_interval.to_seconds()) { + if (i > conf.rotation_interval.to_seconds() && !file_changed ) { std::string rez; fc::read_file_contents(prev_log_filename, rez); std::size_t found = rez.find("my_file.cpp:" + std::to_string(i - 1)); @@ -66,7 +71,10 @@ BOOST_AUTO_TEST_CASE(log_reboot) fc::usleep(fc::seconds(1)); } + if( file_changed_count >= 3 ) { + BOOST_FAIL( "It is not expected that file name changes too frequently" ); + } BOOST_TEST_MESSAGE("Loop complete"); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END()