Skip to content

Commit 154d0b1

Browse files
committed
Obtains the Redis host from env variables.
1 parent 2b12525 commit 154d0b1

15 files changed

+49
-35
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ jobs:
201201
CXXFLAGS: ${{matrix.cxxflags}} -Wall -Wextra
202202
LDFLAGS: ${{matrix.ldflags}}
203203
CMAKE_BUILD_PARALLEL_LEVEL: 4
204+
BOOST_REDIS_TEST_SERVER: redis
204205

205206
services:
206207
redis:

test/common.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "common.hpp"
22
#include <iostream>
3+
#include <cstdlib>
34
#include <boost/asio/consign.hpp>
45
#include <boost/asio/co_spawn.hpp>
56

6-
77
namespace net = boost::asio;
88

99
struct run_callback {
@@ -29,6 +29,27 @@ run(
2929
conn->async_run(cfg, {l}, run_callback{conn, op, ec});
3030
}
3131

32+
std::string safe_getenv(const char* name, const char* default_value)
33+
{
34+
// MSVC doesn't like getenv
35+
#ifdef BOOST_MSVC
36+
#pragma warning(push)
37+
#pragma warning(disable : 4996)
38+
#endif
39+
const char* res = std::getenv(name);
40+
#ifdef BOOST_MSVC
41+
#pragma warning(pop)
42+
#endif
43+
return res ? res : default_value;
44+
}
45+
46+
boost::redis::config make_test_config()
47+
{
48+
boost::redis::config cfg;
49+
cfg.addr.host = safe_getenv("BOOST_REDIS_TEST_SERVER", "localhost");
50+
return cfg;
51+
}
52+
3253
#ifdef BOOST_ASIO_HAS_CO_AWAIT
3354
auto start(net::awaitable<void> op) -> int
3455
{
@@ -48,5 +69,4 @@ auto start(net::awaitable<void> op) -> int
4869

4970
return 1;
5071
}
51-
5272
#endif // BOOST_ASIO_HAS_CO_AWAIT

test/common.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ auto redir(boost::system::error_code& ec)
1515
auto start(boost::asio::awaitable<void> op) -> int;
1616
#endif // BOOST_ASIO_HAS_CO_AWAIT
1717

18+
boost::redis::config make_test_config();
19+
1820
void
1921
run(
2022
std::shared_ptr<boost::redis::connection> conn,
21-
boost::redis::config cfg = {},
23+
boost::redis::config cfg = make_test_config(),
2224
boost::system::error_code ec = boost::asio::error::operation_aborted,
2325
boost::redis::operation op = boost::redis::operation::receive,
2426
boost::redis::logger::level l = boost::redis::logger::level::disabled);

test/test_conn_check_health.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ using boost::redis::ignore;
2222
using boost::redis::operation;
2323
using boost::redis::generic_response;
2424
using boost::redis::consume_one;
25-
using redis::config;
2625

2726
// TODO: Test cancel(health_check)
2827

29-
3028
struct push_callback {
3129
connection* conn1;
3230
connection* conn2;
@@ -73,14 +71,12 @@ struct push_callback {
7371
BOOST_AUTO_TEST_CASE(check_health)
7472
{
7573
net::io_context ioc;
76-
77-
7874
connection conn1{ioc};
7975

8076
request req1;
8177
req1.push("CLIENT", "PAUSE", "10000", "ALL");
8278

83-
config cfg1;
79+
auto cfg1 = make_test_config();
8480
cfg1.health_check_id = "conn1";
8581
cfg1.reconnect_wait_interval = std::chrono::seconds::zero();
8682
error_code res1;
@@ -95,7 +91,7 @@ BOOST_AUTO_TEST_CASE(check_health)
9591
// sending MONITOR. I will therefore open a second connection.
9692
connection conn2{ioc};
9793

98-
config cfg2;
94+
auto cfg2 = make_test_config();
9995
cfg2.health_check_id = "conn2";
10096
error_code res2;
10197
conn2.async_run(cfg2, {}, [&](auto ec){

test/test_conn_echo_stress.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ using boost::redis::response;
2424
using boost::redis::ignore;
2525
using boost::redis::ignore_t;
2626
using boost::redis::logger;
27-
using boost::redis::config;
2827
using boost::redis::connection;
2928
using boost::redis::usage;
3029
using boost::redis::error;
@@ -79,7 +78,7 @@ echo_session(
7978
auto async_echo_stress(std::shared_ptr<connection> conn) -> net::awaitable<void>
8079
{
8180
auto ex = co_await net::this_coro::executor;
82-
config cfg;
81+
auto cfg = make_test_config();
8382
cfg.health_check_interval = std::chrono::seconds::zero();
8483
run(conn, cfg,
8584
boost::asio::error::operation_aborted,

test/test_conn_exec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ using boost::redis::response;
2323
using boost::redis::generic_response;
2424
using boost::redis::ignore;
2525
using boost::redis::operation;
26-
using boost::redis::config;
2726

2827
// Sends three requests where one of them has a hello with a priority
2928
// set, which means it should be executed first.
@@ -122,7 +121,7 @@ BOOST_AUTO_TEST_CASE(cancel_request_if_not_connected)
122121

123122
BOOST_AUTO_TEST_CASE(correct_database)
124123
{
125-
config cfg;
124+
auto cfg = make_test_config();
126125
cfg.database_index = 2;
127126

128127
net::io_context ioc;

test/test_conn_exec_cancel.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ using boost::redis::response;
2929
using boost::redis::generic_response;
3030
using boost::redis::ignore;
3131
using boost::redis::ignore_t;
32-
using boost::redis::config;
3332
using boost::redis::logger;
3433
using boost::redis::connection;
3534
using namespace std::chrono_literals;
@@ -39,8 +38,8 @@ auto implicit_cancel_of_req_written() -> net::awaitable<void>
3938
auto ex = co_await net::this_coro::executor;
4039
auto conn = std::make_shared<connection>(ex);
4140

42-
config cfg;
43-
cfg.health_check_interval = std::chrono::seconds{0};
41+
auto cfg = make_test_config();
42+
cfg.health_check_interval = std::chrono::seconds::zero();
4443
run(conn, cfg);
4544

4645
// See NOTE1.
@@ -106,7 +105,7 @@ BOOST_AUTO_TEST_CASE(test_cancel_of_req_written_on_run_canceled)
106105

107106
conn->async_exec(req0, ignore, c0);
108107

109-
config cfg;
108+
auto cfg = make_test_config();
110109
cfg.health_check_interval = std::chrono::seconds{5};
111110
run(conn);
112111

test/test_conn_exec_error.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ using boost::redis::ignore_t;
2525
using boost::redis::error;
2626
using boost::redis::logger;
2727
using boost::redis::operation;
28-
using redis::config;
2928
using namespace std::chrono_literals;
3029

3130
BOOST_AUTO_TEST_CASE(no_ignore_error)

test/test_conn_exec_retry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(request_retry_false)
7474

7575
conn->async_exec(req0, ignore, c0);
7676

77-
config cfg;
77+
auto cfg = make_test_config();
7878
cfg.health_check_interval = 5s;
7979
run(conn);
8080

@@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(request_retry_true)
137137

138138
conn->async_exec(req0, ignore, c0);
139139

140-
config cfg;
140+
auto cfg = make_test_config();
141141
cfg.health_check_interval = 5s;
142142
conn->async_run(cfg, {}, [&](auto ec){
143143
std::cout << ec.message() << std::endl;

test/test_conn_push.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ using boost::redis::response;
2727
using boost::redis::ignore;
2828
using boost::redis::ignore_t;
2929
using boost::system::error_code;
30-
using redis::config;
3130
using boost::redis::logger;
3231
using namespace std::chrono_literals;
3332

@@ -67,7 +66,7 @@ BOOST_AUTO_TEST_CASE(receives_push_waiting_resps)
6766

6867
conn->async_exec(req1, ignore, c1);
6968

70-
run(conn, {}, {});
69+
run(conn, make_test_config(), {});
7170

7271
bool push_received = false;
7372
conn->async_receive([&, conn](auto ec, auto){
@@ -217,7 +216,8 @@ BOOST_AUTO_TEST_CASE(test_push_adapter)
217216
BOOST_CHECK_EQUAL(ec, boost::system::errc::errc_t::operation_canceled);
218217
});
219218

220-
conn->async_run({}, {}, [](auto ec){
219+
auto cfg = make_test_config();
220+
conn->async_run(cfg, {}, [](auto ec){
221221
BOOST_CHECK_EQUAL(ec, boost::redis::error::incompatible_size);
222222
});
223223

0 commit comments

Comments
 (0)