Skip to content

Commit

Permalink
Update test order to avoid spurious test failures due to timing.
Browse files Browse the repository at this point in the history
copy_file_tests with copy_options::update_existing used to fail sometimes,
when the last modification timestamps on the test files were close enough.
Run the tests after a pause to make sure the timestamps are far enough apart.
  • Loading branch information
Lastique committed Jun 29, 2024
1 parent 9f8dea7 commit c8093ee
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions test/operations_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1929,30 +1929,31 @@ void copy_file_tests(const fs::path& f1x, const fs::path& d1x)
verify_file(d1x / "f2-non-existing", "file-f1");
fs::remove(d1x / "f2-non-existing");

// Sleep for a while so that the last modify time is more recent for new files
#if defined(BOOST_POSIX_API)
sleep(2);
#else
Sleep(2000);
#endif

create_file(d1x / "f2-more-recent", "x");
BOOST_TEST_EQ(fs::file_size(d1x / "f2-more-recent"), 1U);

file_copied = false;
copy_ex_ok = true;
try
{
file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::update_existing);
file_copied = fs::copy_file(d1x / "f2", d1x / "f2-more-recent", fs::copy_options::update_existing);
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = false;
}
BOOST_TEST(copy_ex_ok);
BOOST_TEST(!file_copied);
BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U);
verify_file(d1x / "f2", "1234567890");

// Sleep for a while so that the last modify time is more recent for new files
#if defined(BOOST_POSIX_API)
sleep(2);
#else
Sleep(2000);
#endif

create_file(d1x / "f2-more-recent", "x");
BOOST_TEST_EQ(fs::file_size(d1x / "f2-more-recent"), 1U);
verify_file(d1x / "f2-more-recent", "x");

file_copied = false;
copy_ex_ok = true;
try
Expand Down

0 comments on commit c8093ee

Please sign in to comment.