• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 
10 #define BOOST_TEST_MAIN
11 
12 #include <boost/test/included/unit_test.hpp>
13 #include <boost/process/error.hpp>
14 #include <boost/process/child.hpp>
15 #include <boost/process/args.hpp>
16 #include <boost/process/async.hpp>
17 #include <thread>
18 #include <atomic>
19 #include <system_error>
20 #include <boost/asio.hpp>
21 #if defined(BOOST_POSIX_API)
22 #   include <signal.h>
23 #endif
24 
25 namespace bp = boost::process;
26 
27 BOOST_AUTO_TEST_SUITE( wait_test );
28 
29 
30 BOOST_AUTO_TEST_CASE(sync_wait, *boost::unit_test::timeout(2))
31 {
32     using boost::unit_test::framework::master_test_suite;
33 
34     std::error_code ec;
35     bp::child c(
36         master_test_suite().argv[1],
37         bp::args+={"test", "--wait", "1"},
38         ec
39     );
40     BOOST_REQUIRE(!ec);
41 
42     c.wait();
43 
44 }
45 
46 BOOST_AUTO_TEST_CASE(async_wait, *boost::unit_test::timeout(4))
47 {
48     using boost::unit_test::framework::master_test_suite;
49     using namespace boost::asio;
50 
51     boost::asio::io_context io_context;
52 
53     std::error_code ec;
54     bool called = false;
55 
56     boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(3)};
__anon972e80d90102(boost::system::error_code ec)57     timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();});
58 
59 
60     bp::child c(
61         master_test_suite().argv[1],
62         bp::args+={"test", "--wait", "1"},
63         ec,
64         io_context,
__anon972e80d90202(int, const std::error_code&)65         bp::on_exit([&](int, const std::error_code&){called = true;})
66 
67     );
68     BOOST_REQUIRE(!ec);
69 
70     io_context.run();
71     BOOST_CHECK(called);
72 
73 }
74 
75 BOOST_AUTO_TEST_SUITE_END();
76