// // Copyright (c) 2025 Marcelo Zimbres Silva (mzimbres@gmail.com), // Ruben Perez Hidalgo (rubenperez038 at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include #include #include #include #include #include #include #include "common.hpp" #include #include #include using boost::system::error_code; namespace net = boost::asio; using namespace boost::redis; namespace { // Terminal and partial cancellation work for async_run template void test_per_operation_cancellation(std::string_view name, net::cancellation_type_t cancel_type) { std::cerr << "Running test case: " << name << std::endl; // Setup net::io_context ioc; Connection conn{ioc}; net::cancellation_signal sig; request req; req.push("PING", "something"); bool run_finished = false, exec_finished = false; // Run the connection auto run_cb = [&](error_code ec) { run_finished = true; BOOST_TEST_EQ(ec, net::error::operation_aborted); }; conn.async_run(make_test_config(), net::bind_cancellation_slot(sig.slot(), run_cb)); // Launch a PING conn.async_exec(req, ignore, [&](error_code ec, std::size_t) { exec_finished = true; BOOST_TEST_EQ(ec, error_code()); sig.emit(cancel_type); }); ioc.run_for(test_timeout); // Check BOOST_TEST(run_finished); BOOST_TEST(exec_finished); } } // namespace int main() { using basic_connection_t = basic_connection; test_per_operation_cancellation( "basic_connection, terminal", net::cancellation_type_t::terminal); test_per_operation_cancellation( "basic_connection, partial", net::cancellation_type_t::partial); test_per_operation_cancellation( "connection, terminal", net::cancellation_type_t::terminal); test_per_operation_cancellation( "connection, partial", net::cancellation_type_t::partial); return boost::report_errors(); }