mirror of
https://github.com/boostorg/process.git
synced 2026-01-19 04:22:15 +00:00
simplified terminate test.
This commit is contained in:
committed by
Klemens Morgenstern
parent
d66dce11bd
commit
9a4aeab97e
@@ -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>
|
||||
@@ -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>())
|
||||
{
|
||||
|
||||
@@ -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(
|
||||
@@ -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;
|
||||
@@ -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());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user