diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b3b3612..959d1dc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,46 +53,48 @@ include_directories(include) # Executables #======================================================================= +#add_executable(intro_sync examples/intro_sync.cpp) // Uncomment after update to Boost 1.80 add_executable(chat_room examples/chat_room.cpp) add_executable(containers examples/containers.cpp) add_executable(echo_server examples/echo_server.cpp) +add_executable(echo_server_client benchmarks/cpp/asio/echo_server_client.cpp) +add_executable(echo_server_direct benchmarks/cpp/asio/echo_server_direct.cpp) add_executable(intro examples/intro.cpp) add_executable(intro_tls examples/intro_tls.cpp) -#add_executable(intro_sync examples/intro_sync.cpp) // Uncomment after update to Boost 1.80 +add_executable(low_level_sync examples/low_level_sync.cpp) add_executable(serialization examples/serialization.cpp) add_executable(subscriber examples/subscriber.cpp) add_executable(subscriber_sentinel examples/subscriber_sentinel.cpp) -add_executable(test_low_level tests/low_level.cpp) -add_executable(low_level_sync examples/low_level_sync.cpp) -add_executable(test_connection_other tests/connection_other.cpp) add_executable(test_connection_connect tests/connection_connect.cpp) +add_executable(test_connection_other tests/connection_other.cpp) add_executable(test_connection_push tests/connection_push.cpp) add_executable(test_connection_quit tests/connection_quit.cpp) add_executable(test_connection_quit_coalesce tests/connection_quit_coalesce.cpp) add_executable(test_connection_reconnect tests/connection_reconnect.cpp) add_executable(test_connection_tls tests/connection_tls.cpp) -add_executable(echo_server_client benchmarks/cpp/asio/echo_server_client.cpp) -add_executable(echo_server_direct benchmarks/cpp/asio/echo_server_direct.cpp) +add_executable(test_low_level tests/low_level.cpp) +add_executable(test_cancelation tests/cancelation.cpp) target_compile_features(chat_room PUBLIC cxx_std_20) +target_compile_features(containers PUBLIC cxx_std_17) +target_compile_features(echo_server PUBLIC cxx_std_20) +target_compile_features(echo_server_client PUBLIC cxx_std_20) +target_compile_features(echo_server_direct PUBLIC cxx_std_20) target_compile_features(intro PUBLIC cxx_std_17) target_compile_features(intro_tls PUBLIC cxx_std_17) -target_compile_features(serialization PUBLIC cxx_std_17) -target_compile_features(containers PUBLIC cxx_std_17) -target_compile_features(test_low_level PUBLIC cxx_std_17) target_compile_features(low_level_sync PUBLIC cxx_std_17) -target_compile_features(echo_server PUBLIC cxx_std_20) +target_compile_features(serialization PUBLIC cxx_std_17) target_compile_features(subscriber PUBLIC cxx_std_20) target_compile_features(subscriber_sentinel PUBLIC cxx_std_20) +target_compile_features(test_connection_connect PUBLIC cxx_std_17) target_compile_features(test_connection_other PUBLIC cxx_std_20) target_compile_features(test_connection_push PUBLIC cxx_std_20) -target_compile_features(test_connection_connect PUBLIC cxx_std_17) target_compile_features(test_connection_quit PUBLIC cxx_std_17) target_compile_features(test_connection_quit_coalesce PUBLIC cxx_std_17) target_compile_features(test_connection_reconnect PUBLIC cxx_std_20) target_compile_features(test_connection_tls PUBLIC cxx_std_17) -target_compile_features(echo_server_client PUBLIC cxx_std_20) -target_compile_features(echo_server_direct PUBLIC cxx_std_20) +target_compile_features(test_low_level PUBLIC cxx_std_17) +target_compile_features(test_cancelation PUBLIC cxx_std_20) target_link_libraries(intro_tls OpenSSL::Crypto OpenSSL::SSL) target_link_libraries(test_connection_tls OpenSSL::Crypto OpenSSL::SSL) @@ -114,6 +116,7 @@ add_test(test_connection_quit test_connection_quit) add_test(test_connection_quit_coalesce test_connection_quit_coalesce) add_test(test_connection_reconnect test_connection_reconnect) add_test(test_connection_tls test_connection_tls) +add_test(test_cancelation test_cancelation) # Install #======================================================================= diff --git a/README.md b/README.md index 80690e1b..e6b04408 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,10 @@ int main() } ``` -Requests on the other hand can be sent at any time, regardless of whether before or -after a connection was established. For example, the code below sends -the `PING` and `QUIT` commands, waits for the response and exits +Requests on the other hand can be sent at any time, regardless of +whether before or after a connection was established. For example, the +code below sends the `PING` and `QUIT` commands, waits for the +response and exits ```cpp net::awaitable ping(std::shared_ptr conn) diff --git a/examples/intro.cpp b/examples/intro.cpp index 17b36a50..d9451ffd 100644 --- a/examples/intro.cpp +++ b/examples/intro.cpp @@ -35,6 +35,7 @@ auto main() -> int std::tuple resp; conn.async_exec(req, adapt(resp), logger); conn.async_run({"127.0.0.1", "6379"}, {}, logger); + ioc.run(); std::cout << std::get<0>(resp) << std::endl; diff --git a/include/aedis/resp3/request.hpp b/include/aedis/resp3/request.hpp index 7343604a..24f6cc8c 100644 --- a/include/aedis/resp3/request.hpp +++ b/include/aedis/resp3/request.hpp @@ -181,7 +181,7 @@ public: * called while there is no connection with Redis. The default * behaviour is not to close requests. */ - bool fail_on_connection_lost = false; // TODO: Change the default to true. + bool fail_on_connection_lost = false; /** @brief Coalesce this with other requests. * @@ -196,13 +196,15 @@ public: * before the connection with Redis is stablished. */ bool fail_if_not_connected = false; + + // TODO: Add retry flag. }; /** @brief Constructor * * @param cfg Configuration options. */ - explicit request(config cfg = config{false, true, false}) // TODO: Here too. + explicit request(config cfg = config{false, true, false}) : cfg_{cfg} {} diff --git a/tests/cancelation.cpp b/tests/cancelation.cpp new file mode 100644 index 00000000..d3d2d59b --- /dev/null +++ b/tests/cancelation.cpp @@ -0,0 +1,56 @@ +/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com) + * + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE.txt) + */ + +#include +#include +#include +#include + +#define BOOST_TEST_MODULE low level +#include + +#include +#include + +namespace net = boost::asio; + +using aedis::resp3::request; +using aedis::adapt; +using connection = aedis::connection<>; +using endpoint = aedis::endpoint; +using error_code = boost::system::error_code; +using net::experimental::as_tuple; + +#ifdef BOOST_ASIO_HAS_CO_AWAIT +#include +using namespace net::experimental::awaitable_operators; + +auto async_test_cancel_run() -> net::awaitable +{ + auto ex = co_await net::this_coro::executor; + auto conn = std::make_shared(ex); + net::steady_timer st{ex}; + st.expires_after(std::chrono::seconds{1}); + + endpoint ep{"127.0.0.1", "6379"}; + boost::system::error_code ec1, ec2; + co_await ( + conn->async_run(ep, {}, net::redirect_error(net::use_awaitable, ec1)) || + st.async_wait(net::redirect_error(net::use_awaitable, ec2)) + ); + + BOOST_CHECK_EQUAL(ec1, boost::asio::error::basic_errors::operation_aborted); + BOOST_TEST(!ec2); +} + +BOOST_AUTO_TEST_CASE(test_cancel_run) +{ + std::cout << boost::unit_test::framework::current_test_case().p_name << std::endl; + net::io_context ioc; + net::co_spawn(ioc.get_executor(), async_test_cancel_run(), net::detached); + ioc.run(); +} +#endif diff --git a/tests/connection_reconnect.cpp b/tests/connection_reconnect.cpp index 7191f22b..adbcb227 100644 --- a/tests/connection_reconnect.cpp +++ b/tests/connection_reconnect.cpp @@ -97,6 +97,6 @@ BOOST_AUTO_TEST_CASE(test_reconnect_timeout) net::co_spawn(ioc, async_test_reconnect_timeout(), net::detached); ioc.run(); } -#elif +#else int main(){} #endif