Skip to content

Commit

Permalink
simplified terminate test.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Jun 20, 2023
1 parent 704bd43 commit 390bb11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
4 changes: 3 additions & 1 deletion test/sparring_partner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <thread>
#if defined(BOOST_POSIX_API)
# include <boost/lexical_cast.hpp>
# include <boost/iostreams/device/file_descriptor.hpp>
Expand Down Expand Up @@ -148,7 +149,8 @@ int main(int argc, char *argv[])
}
else if (vm["loop"].as<bool>())
{
while (true);
while (true)
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
else if (vm["abort"].as<bool>())
{
Expand Down
39 changes: 3 additions & 36 deletions test/terminate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ namespace bp = boost::process;

BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5))
{
std::atomic<bool> done{false};
std::thread thr{
[&]
{
for (int i = 0; i < 50 && !done.load(); i++)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
BOOST_REQUIRE(done.load());
}};

using boost::unit_test::framework::master_test_suite;
std::error_code ec;
bp::child c(
Expand All @@ -44,31 +35,14 @@ BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5))

BOOST_CHECK(c.valid());
BOOST_CHECK(c.running(ec));

BOOST_CHECK_MESSAGE(!c.wait_for(std::chrono::milliseconds(100), ec), ec.message());
BOOST_CHECK_MESSAGE(c.running(ec), ec.message());
BOOST_CHECK(c.valid());

c.terminate(ec);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
BOOST_CHECK(!c.running(ec));
BOOST_CHECK(!ec);

done.store(true);
thr.join();
}

BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5))
{
std::atomic<bool> done{false};
std::thread thr{
[&]
{
for (int i = 0; i < 50 && !done.load(); i++)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
BOOST_REQUIRE(done.load());
}};

using boost::unit_test::framework::master_test_suite;

std::error_code ec;
Expand All @@ -79,17 +53,10 @@ BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5))
ec
);
BOOST_REQUIRE(!ec);
BOOST_CHECK(c.valid());
BOOST_CHECK(c.running());

BOOST_CHECK(!c.wait_for(std::chrono::milliseconds(100), ec));
BOOST_CHECK(c.running(ec));
BOOST_CHECK(c.valid());

BOOST_CHECK(c.running());
c.terminate();
std::this_thread::sleep_for(std::chrono::milliseconds(5));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
BOOST_CHECK(!c.running());

done.store(true);
thr.join();
}

0 comments on commit 390bb11

Please sign in to comment.