Skip to content

Commit

Permalink
fixed executor reset_cancellation_state.
Browse files Browse the repository at this point in the history
Closes #338.
  • Loading branch information
klemens-morgenstern committed Sep 11, 2023
1 parent 502dc48 commit a3259dc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/boost/process/v2/execute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct execute_op
template<typename Self>
void operator()(Self && self)
{
self.reset_cancellation_state();
self.reset_cancellation_state(BOOST_PROCESS_V2_ASIO_NAMESPACE::enable_total_cancellation());
BOOST_PROCESS_V2_ASIO_NAMESPACE::cancellation_slot s = self.get_cancellation_state().slot();
if (s.is_connected())
s.emplace<cancel>(proc.get());
Expand Down
60 changes: 59 additions & 1 deletion test/v2/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include <boost/test/unit_test.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/connect_pipe.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/readable_pipe.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/writable_pipe.hpp>

Expand Down Expand Up @@ -184,7 +186,10 @@ BOOST_AUTO_TEST_CASE(interrupt)

auto sh = interruptable();
BOOST_CHECK_MESSAGE(!sh.empty(), sh);
bpv::process proc(ctx, sh, {}

asio::writable_pipe wp{ctx};

bpv::process proc(ctx, sh, {}, bpv::process_stdio{wp}
#if defined(ASIO_WINDOWS)
, asio::windows::create_new_process_group
#endif
Expand Down Expand Up @@ -585,5 +590,58 @@ BOOST_AUTO_TEST_CASE(bind_launcher)
BOOST_CHECK_MESSAGE(proc.exit_code() == 0, proc.exit_code() << " from " << proc.native_exit_code());
}

BOOST_AUTO_TEST_CASE(async_interrupt)
{
asio::io_context ctx;

auto sh = interruptable();
BOOST_CHECK_MESSAGE(!sh.empty(), sh);
BOOST_CHECK_MESSAGE(!sh.empty(), sh);

asio::writable_pipe wp{ctx};
bpv::process proc(ctx, sh, {}, bpv::process_stdio{wp}
#if defined(ASIO_WINDOWS)
, asio::windows::create_new_process_group
#endif
);

asio::steady_timer tim{ctx, std::chrono::milliseconds(50)};
asio::cancellation_signal sig;

bpv::async_execute(std::move(proc),
asio::bind_cancellation_slot(sig.slot(), asio::detached));

tim.async_wait([&](bpv::error_code ec) { sig.emit(asio::cancellation_type::total); });
ctx.run();
}

BOOST_AUTO_TEST_CASE(async_request_exit)
{
asio::io_context ctx;

auto sh = closable();
BOOST_CHECK_MESSAGE(!sh.empty(), sh);

asio::readable_pipe rp{ctx};
asio::writable_pipe wp{ctx};
asio::connect_pipe(rp, wp);

bpv::process proc(ctx, sh, {}, bpv::process_stdio{rp}
#if defined(ASIO_WINDOWS)
, asio::windows::show_window_minimized_not_active
#endif
);

asio::steady_timer tim{ctx, std::chrono::milliseconds(50)};
asio::cancellation_signal sig;

bpv::async_execute(std::move(proc),
asio::bind_cancellation_slot(sig.slot(), asio::detached));

tim.async_wait([&](bpv::error_code ec) { sig.emit(asio::cancellation_type::partial); });
ctx.run();
}


BOOST_AUTO_TEST_SUITE_END();

0 comments on commit a3259dc

Please sign in to comment.