]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/on_exit2.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / test / on_exit2.cpp
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 #define BOOST_TEST_IGNORE_SIGCHLD
12 #include <boost/test/included/unit_test.hpp>
13 #include <boost/process.hpp>
14 #include <boost/asio.hpp>
15 #include <chrono>
16 #include <thread>
17
18 BOOST_AUTO_TEST_CASE(double_ios, *boost::unit_test::timeout(6))
19 {
20 using boost::unit_test::framework::master_test_suite;
21
22 if (master_test_suite().argc > 2 && strcmp(master_test_suite().argv[1], "sleep") == 0)
23 {
24 auto s = atoi(master_test_suite().argv[2]);
25 std::this_thread::sleep_for(std::chrono::seconds(s));
26 return;
27 }
28
29 namespace bp = boost::process;
30 boost::asio::io_context ios;
31 std::chrono::steady_clock::time_point p1, p2;
32
33 // launch a child that will sleep for 2s
34 auto c1 = bp::child(master_test_suite().argv[0], "sleep", "2", ios,
35 bp::on_exit([&p1](int, const std::error_code&)
36 { p1 = std::chrono::steady_clock::now(); }));
37
38 // wait a bit, make sure the child launch for my test
39 std::this_thread::sleep_for(std::chrono::milliseconds(10));
40
41 // launch a child that will sleep for 4s
42 auto c2 = bp::child(master_test_suite().argv[0], "sleep", "4", ios,
43 bp::on_exit([&p2](int, const std::error_code&)
44 { p2 = std::chrono::steady_clock::now(); }));
45
46
47 ios.run();
48 BOOST_REQUIRE((p2 - p1) > std::chrono::seconds(1));
49 }
50