Skip to content

Commit

Permalink
Merge pull request #222 from bitshares/abitmore-patch-1
Browse files Browse the repository at this point in the history
Deal with a race condition in logging tests
  • Loading branch information
abitmore authored Jan 4, 2021
2 parents a93b4b6 + 9fb25cb commit df83551
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/logging_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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()
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit df83551

Please sign in to comment.