mirror of
https://github.com/boostorg/redis.git
synced 2026-01-19 04:42:09 +00:00
Adds cancelation test.
This commit is contained in:
@@ -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
|
||||
#=======================================================================
|
||||
|
||||
@@ -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<void> ping(std::shared_ptr<connection> conn)
|
||||
|
||||
@@ -35,6 +35,7 @@ auto main() -> int
|
||||
std::tuple<std::string, aedis::ignore> 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;
|
||||
|
||||
@@ -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}
|
||||
{}
|
||||
|
||||
|
||||
56
tests/cancelation.cpp
Normal file
56
tests/cancelation.cpp
Normal file
@@ -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 <iostream>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/system/errc.hpp>
|
||||
#include <boost/asio/experimental/as_tuple.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE low level
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include <aedis.hpp>
|
||||
#include <aedis/src.hpp>
|
||||
|
||||
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 <boost/asio/experimental/awaitable_operators.hpp>
|
||||
using namespace net::experimental::awaitable_operators;
|
||||
|
||||
auto async_test_cancel_run() -> net::awaitable<void>
|
||||
{
|
||||
auto ex = co_await net::this_coro::executor;
|
||||
auto conn = std::make_shared<connection>(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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user