Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions test/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <boost/process/io.hpp>
#include <boost/process/child.hpp>

#include <boost/thread.hpp>
#include <future>

#include <boost/system/error_code.hpp>
Expand Down Expand Up @@ -182,11 +181,11 @@ BOOST_AUTO_TEST_CASE(async_wait_different_contexts, *boost::unit_test::timeout(1
BOOST_REQUIRE(!ec);

// Regression test for #143: make sure each io_context handles its own children
std::thread thr1{[&]{io_context1.run();}};
std::thread thr2{[&]{io_context2.run();}};
std::future<void> thread1 = std::async(std::launch::async, [&]{io_context1.run();});
std::future<void> thread2 = std::async(std::launch::async, [&]{io_context2.run();});

thr1.join();
thr2.join();
thread1.get();
thread2.get();
c1.wait(ec);
BOOST_REQUIRE(!ec);

Expand Down Expand Up @@ -404,12 +403,12 @@ BOOST_AUTO_TEST_CASE(mixed_async, *boost::unit_test::timeout(5))
);

BOOST_REQUIRE(!ec);
std::thread thr([&]{c.wait();});
std::future<void> thread = std::async(std::launch::async, [&]{c.wait();});
io_context.run();

BOOST_CHECK(exit_called);
BOOST_CHECK_EQUAL(c.exit_code(), 42);
thr.join();
thread.get();

}*/

Expand Down
19 changes: 9 additions & 10 deletions test/async_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <thread>
#include <vector>
#include <boost/algorithm/string/predicate.hpp>
#include <future>

#include <boost/process/async_pipe.hpp>
#include <boost/process/pipe.hpp>
Expand Down Expand Up @@ -70,21 +71,19 @@ BOOST_AUTO_TEST_CASE(closed_transform)
BOOST_AUTO_TEST_CASE(multithreaded_async_pipe)
{
asio::io_context ioc;

std::vector<std::thread> threads;
std::vector<std::future<void>> threads;
for (int i = 0; i < std::thread::hardware_concurrency(); i++)
{
threads.emplace_back([&ioc]
threads.emplace_back(std::async(std::launch::async, [&ioc]
{
std::vector<bp::async_pipe*> pipes;
std::vector<std::unique_ptr<bp::async_pipe>> pipes;
for (size_t i = 0; i < 100; i++)
pipes.push_back(new bp::async_pipe(ioc));
for (auto &p : pipes)
delete p;
});
pipes.emplace_back(std::make_unique<bp::async_pipe>(ioc));
}));
}
for (auto &future : threads) {
future.get();
}
for (auto &t : threads)
t.join();
}


Expand Down
15 changes: 9 additions & 6 deletions test/group_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <boost/process/group.hpp>
#include <system_error>

#include <future>
#include <string>
#include <thread>
#include <istream>
Expand All @@ -34,13 +35,14 @@ namespace bp = boost::process;
BOOST_AUTO_TEST_CASE(wait_group_test, *boost::unit_test::timeout(5))
{
std::atomic<bool> done{false};
std::thread thr{
std::future<void> thread = std::async(std::launch::async,
[&]
{
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;
Expand Down Expand Up @@ -77,7 +79,7 @@ BOOST_AUTO_TEST_CASE(wait_group_test, *boost::unit_test::timeout(5))
BOOST_CHECK(!c2.running());

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


Expand All @@ -86,13 +88,14 @@ BOOST_AUTO_TEST_CASE(wait_group_test_timeout, *boost::unit_test::timeout(15))
using boost::unit_test::framework::master_test_suite;

std::atomic<bool> done{false};
std::thread thr{
std::future<void> thread = std::async(std::launch::async,
[&]
{
for (int i = 0; i < 150 && !done.load(); i++)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
BOOST_REQUIRE(done.load());
}};
}
);

std::error_code ec;
bp::group g;
Expand Down Expand Up @@ -131,5 +134,5 @@ BOOST_AUTO_TEST_CASE(wait_group_test_timeout, *boost::unit_test::timeout(15))
BOOST_CHECK(!c2.running());

done.store(true);
thr.join();
thread.get();
}
2 changes: 1 addition & 1 deletion test/on_exit3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(double_ios_threaded, *boost::unit_test::timeout(6))
{ p2 = std::chrono::steady_clock::now(); }));

// wait for the notifications
std::thread ([&ios] { ios.run(); }).join();
ios.run();

BOOST_REQUIRE((p2 - p1) > std::chrono::seconds(1));
}
Expand Down
6 changes: 3 additions & 3 deletions test/pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <boost/test/included/unit_test.hpp>
#include <iostream>
#include <thread>
#include <future>

#include <boost/process/pipe.hpp>
#include <boost/process/environment.hpp>
Expand Down Expand Up @@ -246,11 +246,11 @@ BOOST_AUTO_TEST_CASE(large_data, *boost::unit_test::timeout(20))
for (auto & c: in)
c = (cnt++ % 26) + 'A';

std::thread th([&]{os << in << std::endl;});
std::future<void> thread = std::async(std::launch::async, [&]{os << in << std::endl;});

is >> out;
BOOST_REQUIRE_EQUAL_COLLECTIONS(out.begin(), out.end(), in.begin(), in.end());
th.join();
thread.get();
}

BOOST_AUTO_TEST_CASE(closed, *boost::unit_test::timeout(2))
Expand Down
15 changes: 9 additions & 6 deletions test/terminate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <boost/process/exe.hpp>
#include <boost/process/child.hpp>
#include <boost/process/args.hpp>
#include <future>
#include <system_error>
#include <thread>

Expand All @@ -25,13 +26,14 @@ 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{
std::future<void> thread = std::async(std::launch::async,
[&]
{
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 @@ -55,19 +57,20 @@ BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5))
BOOST_CHECK(!ec);

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

BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5))
{
std::atomic<bool> done{false};
std::thread thr{
std::future<void> thread = std::async(std::launch::async,
[&]
{
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;

Expand All @@ -91,5 +94,5 @@ BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5))
BOOST_CHECK(!c.running());

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