Skip to content

Commit 7caea92

Browse files
authored
Merge pull request #167 from boostorg/165-support-containers-in-ci
165 support containers in ci
2 parents 0bcbf6d + 71b9a4f commit 7caea92

17 files changed

+157
-57
lines changed

.github/workflows/ci.yml

Lines changed: 103 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,98 @@ jobs:
131131
fail-fast: false
132132
matrix:
133133
include:
134-
- { toolset: gcc-11, install: g++-11, os: ubuntu-22.04, cxxstd: '17', build-type: 'Debug', ldflags: '' }
135-
- { toolset: gcc-11, install: g++-11, os: ubuntu-22.04, cxxstd: '20', build-type: 'Release', ldflags: '' }
136-
- { toolset: clang-11, install: clang-11, os: ubuntu-22.04, cxxstd: '17', build-type: 'Debug', ldflags: '' }
137-
- { toolset: clang-11, install: clang-11, os: ubuntu-22.04, cxxstd: '20', build-type: 'Debug', ldflags: '' }
138-
- { toolset: clang-13, install: clang-13, os: ubuntu-22.04, cxxstd: '17', build-type: 'Release', ldflags: '' }
139-
- { toolset: clang-13, install: clang-13, os: ubuntu-22.04, cxxstd: '20', build-type: 'Release', ldflags: '' }
140-
- { toolset: clang-14, install: 'clang-14 libc++-14-dev libc++abi-14-dev', os: ubuntu-22.04, cxxstd: '17', build-type: 'Debug', cxxflags: '-stdlib=libc++', ldflags: '-lc++' }
141-
- { toolset: clang-14, install: 'clang-14 libc++-14-dev libc++abi-14-dev', os: ubuntu-22.04, cxxstd: '20', build-type: 'Release', cxxflags: '-stdlib=libc++', ldflags: '-lc++' }
134+
- toolset: gcc-11
135+
install: g++-11
136+
os: ubuntu-latest
137+
container: ubuntu:22.04
138+
cxxstd: '17'
139+
build-type: 'Debug'
140+
ldflags: ''
141+
142+
- toolset: gcc-11
143+
install: g++-11
144+
os: ubuntu-latest
145+
container: ubuntu:22.04
146+
cxxstd: '20'
147+
build-type: 'Release'
148+
ldflags: ''
149+
150+
- toolset: clang-11
151+
install: clang-11
152+
os: ubuntu-latest
153+
container: ubuntu:22.04
154+
cxxstd: '17'
155+
build-type: 'Debug'
156+
ldflags: ''
157+
158+
- toolset: clang-11
159+
install: clang-11
160+
os: ubuntu-latest
161+
container: ubuntu:22.04
162+
cxxstd: '20'
163+
build-type: 'Debug'
164+
ldflags: ''
165+
166+
- toolset: clang-13
167+
install: clang-13
168+
os: ubuntu-latest
169+
container: ubuntu:22.04
170+
cxxstd: '17'
171+
build-type: 'Release'
172+
ldflags: ''
173+
174+
- toolset: clang-13
175+
install: clang-13
176+
os: ubuntu-latest
177+
container: ubuntu:22.04
178+
cxxstd: '20'
179+
build-type: 'Release'
180+
ldflags: ''
181+
182+
- toolset: clang-14
183+
install: 'clang-14 libc++-14-dev libc++abi-14-dev'
184+
os: ubuntu-latest
185+
container: ubuntu:22.04
186+
cxxstd: '17'
187+
build-type: 'Debug'
188+
cxxflags: '-stdlib=libc++'
189+
ldflags: '-lc++'
190+
191+
- toolset: clang-14
192+
install: 'clang-14 libc++-14-dev libc++abi-14-dev'
193+
os: ubuntu-latest
194+
container: ubuntu:22.04
195+
cxxstd: '20'
196+
build-type: 'Release'
197+
cxxflags: '-stdlib=libc++'
198+
ldflags: '-lc++'
199+
142200
runs-on: ${{ matrix.os }}
201+
container: ${{matrix.container}}
143202
env:
144203
CXXFLAGS: ${{matrix.cxxflags}} -Wall -Wextra
145204
LDFLAGS: ${{matrix.ldflags}}
146205
CMAKE_BUILD_PARALLEL_LEVEL: 4
206+
BOOST_REDIS_TEST_SERVER: redis
207+
208+
services:
209+
redis:
210+
image: redis
211+
147212
steps:
148213
- name: Checkout
149214
uses: actions/checkout@v3
150215

216+
- name: Setup container environment
217+
if: matrix.container
218+
run: |
219+
apt-get update
220+
apt-get -y install sudo python3 git g++ libssl-dev protobuf-compiler redis-server
221+
151222
- name: Install dependencies
152-
run: sudo apt-get -y install cmake protobuf-compiler redis-server python3 ${{ matrix.install }}
223+
run: |
224+
sudo apt-get update
225+
sudo apt-get -y install cmake protobuf-compiler redis-server python3 ${{ matrix.install }}
153226
154227
- name: Setup Boost
155228
run: ./tools/ci.py setup-boost --source-dir=$(pwd)
@@ -209,15 +282,32 @@ jobs:
209282
fail-fast: false
210283
matrix:
211284
include:
212-
- { toolset: gcc-11, install: g++-11, cxxstd: "11,17,20" } # Having C++11 shouldn't break the build
213-
- { toolset: clang-14, install: clang-14, cxxstd: "17,20" }
214-
runs-on: ubuntu-22.04
285+
- toolset: gcc-11
286+
install: g++-11
287+
cxxstd: "11,17,20" # Having C++11 shouldn't break the build
288+
os: ubuntu-latest
289+
container: ubuntu:22.04
290+
- toolset: clang-14
291+
install: clang-14
292+
os: ubuntu-latest
293+
container: ubuntu:22.04
294+
cxxstd: "17,20"
295+
runs-on: ${{ matrix.os }}
296+
container: ${{matrix.container}}
215297
steps:
216298
- name: Checkout
217299
uses: actions/checkout@v3
218300

301+
- name: Setup container environment
302+
if: matrix.container
303+
run: |
304+
apt-get update
305+
apt-get -y install sudo python3 git g++ libssl-dev
306+
219307
- name: Install dependencies
220-
run: sudo apt-get -y install python3 ${{ matrix.install }}
308+
run: |
309+
sudo apt-get update
310+
sudo apt-get -y install python3 ${{ matrix.install }}
221311
222312
- name: Setup Boost
223313
run: ./tools/ci.py setup-boost --source-dir=$(pwd)

test/cmake_subdir_test/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ project(cmake_subdir_test LANGUAGES CXX)
55
set(BOOST_INCLUDE_LIBRARIES redis)
66

77
# Build our dependencies, so the targets Boost::xxx are defined
8-
add_subdirectory(${_BOOST_ROOT} boostorg/boost)
9-
10-
# Build our project
11-
add_subdirectory(${_BOOST_ROOT}/libs/redis boostorg/redis)
8+
add_subdirectory(../../../.. boostorg/boost)
129

1310
add_executable(main main.cpp)
1411
target_link_libraries(main PRIVATE Boost::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: 4 additions & 5 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,
@@ -92,14 +91,14 @@ auto async_echo_stress(std::shared_ptr<connection> conn) -> net::awaitable<void>
9291

9392
// Number of coroutines that will send pings sharing the same
9493
// connection to redis.
95-
int const sessions = 1000;
94+
int const sessions = 150;
9695

9796
// The number of pings that will be sent by each session.
98-
int const msgs = 500;
97+
int const msgs = 200;
9998

10099
// The number of publishes that will be sent by each session with
101100
// each message.
102-
int const n_pubs = 100;
101+
int const n_pubs = 25;
103102

104103
// This is the total number of pushes we will receive.
105104
int total_pushes = sessions * msgs * n_pubs + 1;

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: 4 additions & 4 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

@@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(many_subscribers)
319319

320320
conn->async_exec(req0, ignore, c0);
321321

322-
run(conn, {}, {});
322+
run(conn, make_test_config(), {});
323323

324324
net::co_spawn(ioc.get_executor(), push_consumer3(conn), net::detached);
325325
ioc.run();

0 commit comments

Comments
 (0)