Skip to content

Commit f5f57e3

Browse files
committed
Improvements in the redis-push stress test.
1 parent 7abfc5f commit f5f57e3

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

tests/common.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ run(
2525
std::shared_ptr<boost::redis::connection> conn,
2626
boost::redis::config cfg,
2727
boost::system::error_code ec,
28-
boost::redis::operation op)
28+
boost::redis::operation op,
29+
boost::redis::logger::level l)
2930
{
30-
conn->async_run(cfg, {}, run_callback{conn, op, ec});
31+
conn->async_run(cfg, {l}, run_callback{conn, op, ec});
3132
}
3233

3334
#ifdef BOOST_ASIO_HAS_CO_AWAIT

tests/common.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ run(
2020
std::shared_ptr<boost::redis::connection> conn,
2121
boost::redis::config cfg = {},
2222
boost::system::error_code ec = boost::asio::error::operation_aborted,
23-
boost::redis::operation op = boost::redis::operation::receive);
23+
boost::redis::operation op = boost::redis::operation::receive,
24+
boost::redis::logger::level l = boost::redis::logger::level::info);
2425

tests/test_conn_echo_stress.cpp

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <boost/redis/connection.hpp>
88
#include <boost/asio/co_spawn.hpp>
99
#include <boost/asio/detached.hpp>
10+
#include <boost/asio/deferred.hpp>
1011
#include <boost/system/errc.hpp>
1112
#define BOOST_TEST_MODULE echo-stress
1213
#include <boost/test/included/unit_test.hpp>
@@ -38,44 +39,75 @@ auto push_consumer(std::shared_ptr<connection> conn, int expected) -> net::await
3839
conn->cancel();
3940
}
4041

41-
auto echo_session(std::shared_ptr<connection> conn, std::string id, int n) -> net::awaitable<void>
42+
auto
43+
echo_session(
44+
std::shared_ptr<connection> conn,
45+
std::shared_ptr<request> pubs,
46+
std::string id,
47+
int n) -> net::awaitable<void>
4248
{
4349
auto ex = co_await net::this_coro::executor;
4450

4551
request req;
46-
response<ignore_t, std::string> resp;
52+
response<ignore_t, std::string, ignore_t> resp;
4753

4854
for (auto i = 0; i < n; ++i) {
4955
auto const msg = id + "/" + std::to_string(i);
5056
//std::cout << msg << std::endl;
51-
req.push("HELLO", 3);
57+
req.push("HELLO", 3); // Just to mess around.
5258
req.push("PING", msg);
53-
req.push("SUBSCRIBE", "channel");
59+
req.push("PING", "lsls"); // TODO: Change to HELLO after fixing issue 105.
5460
boost::system::error_code ec;
5561
co_await conn->async_exec(req, resp, redir(ec));
56-
BOOST_CHECK_EQUAL(ec, boost::system::error_code{});
57-
BOOST_CHECK_EQUAL(msg, std::get<1>(resp).value());
62+
63+
BOOST_REQUIRE_EQUAL(ec, boost::system::error_code{});
64+
BOOST_REQUIRE_EQUAL(msg, std::get<1>(resp).value());
5865
req.clear();
5966
std::get<1>(resp).value().clear();
67+
68+
co_await conn->async_exec(*pubs, ignore, net::deferred);
6069
}
6170
}
6271

6372
auto async_echo_stress() -> net::awaitable<void>
6473
{
6574
auto ex = co_await net::this_coro::executor;
6675
auto conn = std::make_shared<connection>(ex);
76+
config cfg;
77+
cfg.health_check_interval = std::chrono::seconds::zero();
78+
run(conn, cfg,
79+
boost::asio::error::operation_aborted,
80+
boost::redis::operation::receive,
81+
boost::redis::logger::level::crit);
82+
83+
request req;
84+
req.push("SUBSCRIBE", "channel");
85+
co_await conn->async_exec(req, ignore, net::deferred);
6786

87+
// Number of coroutines that will send pings sharing the same
88+
// connection to redis.
6889
int const sessions = 500;
90+
91+
// The number of pings that will be sent by each session.
6992
int const msgs = 1000;
70-
int total = sessions * msgs;
7193

72-
net::co_spawn(ex, push_consumer(conn, total), net::detached);
94+
// The number of publishes that will be sent by each session with
95+
// each message.
96+
int const n_pubs = 10;
7397

74-
for (int i = 0; i < sessions; ++i)
75-
net::co_spawn(ex, echo_session(conn, std::to_string(i), msgs), net::detached);
98+
// This is the total number of pushes we will receive.
99+
int total_pushes = sessions * msgs * n_pubs + 1;
76100

101+
auto pubs = std::make_shared<request>();
102+
for (int i = 0; i < n_pubs; ++i)
103+
pubs->push("PUBLISH", "channel", "payload");
77104

78-
run(conn);
105+
// Op that will consume the pushes counting down until all expected
106+
// pushes have been received.
107+
net::co_spawn(ex, push_consumer(conn, total_pushes), net::detached);
108+
109+
for (int i = 0; i < sessions; ++i)
110+
net::co_spawn(ex, echo_session(conn, pubs, std::to_string(i), msgs), net::detached);
79111
}
80112

81113
BOOST_AUTO_TEST_CASE(echo_stress)

0 commit comments

Comments
 (0)