Skip to content

Commit

Permalink
Merge pull request #167 from boostorg/165-support-containers-in-ci
Browse files Browse the repository at this point in the history
165 support containers in ci
  • Loading branch information
mzimbres authored Nov 12, 2023
2 parents 0bcbf6d + 71b9a4f commit 7caea92
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 57 deletions.
116 changes: 103 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,98 @@ jobs:
fail-fast: false
matrix:
include:
- { toolset: gcc-11, install: g++-11, os: ubuntu-22.04, cxxstd: '17', build-type: 'Debug', ldflags: '' }
- { toolset: gcc-11, install: g++-11, os: ubuntu-22.04, cxxstd: '20', build-type: 'Release', ldflags: '' }
- { toolset: clang-11, install: clang-11, os: ubuntu-22.04, cxxstd: '17', build-type: 'Debug', ldflags: '' }
- { toolset: clang-11, install: clang-11, os: ubuntu-22.04, cxxstd: '20', build-type: 'Debug', ldflags: '' }
- { toolset: clang-13, install: clang-13, os: ubuntu-22.04, cxxstd: '17', build-type: 'Release', ldflags: '' }
- { toolset: clang-13, install: clang-13, os: ubuntu-22.04, cxxstd: '20', build-type: 'Release', ldflags: '' }
- { 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++' }
- { 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++' }
- toolset: gcc-11
install: g++-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Debug'
ldflags: ''

- toolset: gcc-11
install: g++-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Release'
ldflags: ''

- toolset: clang-11
install: clang-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Debug'
ldflags: ''

- toolset: clang-11
install: clang-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Debug'
ldflags: ''

- toolset: clang-13
install: clang-13
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Release'
ldflags: ''

- toolset: clang-13
install: clang-13
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Release'
ldflags: ''

- toolset: clang-14
install: 'clang-14 libc++-14-dev libc++abi-14-dev'
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Debug'
cxxflags: '-stdlib=libc++'
ldflags: '-lc++'

- toolset: clang-14
install: 'clang-14 libc++-14-dev libc++abi-14-dev'
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Release'
cxxflags: '-stdlib=libc++'
ldflags: '-lc++'

runs-on: ${{ matrix.os }}
container: ${{matrix.container}}
env:
CXXFLAGS: ${{matrix.cxxflags}} -Wall -Wextra
LDFLAGS: ${{matrix.ldflags}}
CMAKE_BUILD_PARALLEL_LEVEL: 4
BOOST_REDIS_TEST_SERVER: redis

services:
redis:
image: redis

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python3 git g++ libssl-dev protobuf-compiler redis-server
- name: Install dependencies
run: sudo apt-get -y install cmake protobuf-compiler redis-server python3 ${{ matrix.install }}
run: |
sudo apt-get update
sudo apt-get -y install cmake protobuf-compiler redis-server python3 ${{ matrix.install }}
- name: Setup Boost
run: ./tools/ci.py setup-boost --source-dir=$(pwd)
Expand Down Expand Up @@ -209,15 +282,32 @@ jobs:
fail-fast: false
matrix:
include:
- { toolset: gcc-11, install: g++-11, cxxstd: "11,17,20" } # Having C++11 shouldn't break the build
- { toolset: clang-14, install: clang-14, cxxstd: "17,20" }
runs-on: ubuntu-22.04
- toolset: gcc-11
install: g++-11
cxxstd: "11,17,20" # Having C++11 shouldn't break the build
os: ubuntu-latest
container: ubuntu:22.04
- toolset: clang-14
install: clang-14
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: "17,20"
runs-on: ${{ matrix.os }}
container: ${{matrix.container}}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python3 git g++ libssl-dev
- name: Install dependencies
run: sudo apt-get -y install python3 ${{ matrix.install }}
run: |
sudo apt-get update
sudo apt-get -y install python3 ${{ matrix.install }}
- name: Setup Boost
run: ./tools/ci.py setup-boost --source-dir=$(pwd)
Expand Down
5 changes: 1 addition & 4 deletions test/cmake_subdir_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ project(cmake_subdir_test LANGUAGES CXX)
set(BOOST_INCLUDE_LIBRARIES redis)

# Build our dependencies, so the targets Boost::xxx are defined
add_subdirectory(${_BOOST_ROOT} boostorg/boost)

# Build our project
add_subdirectory(${_BOOST_ROOT}/libs/redis boostorg/redis)
add_subdirectory(../../../.. boostorg/boost)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE Boost::redis)
Expand Down
24 changes: 22 additions & 2 deletions test/common.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "common.hpp"
#include <iostream>
#include <cstdlib>
#include <boost/asio/consign.hpp>
#include <boost/asio/co_spawn.hpp>


namespace net = boost::asio;

struct run_callback {
Expand All @@ -29,6 +29,27 @@ run(
conn->async_run(cfg, {l}, run_callback{conn, op, ec});
}

std::string safe_getenv(const char* name, const char* default_value)
{
// MSVC doesn't like getenv
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
const char* res = std::getenv(name);
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
return res ? res : default_value;
}

boost::redis::config make_test_config()
{
boost::redis::config cfg;
cfg.addr.host = safe_getenv("BOOST_REDIS_TEST_SERVER", "localhost");
return cfg;
}

#ifdef BOOST_ASIO_HAS_CO_AWAIT
auto start(net::awaitable<void> op) -> int
{
Expand All @@ -48,5 +69,4 @@ auto start(net::awaitable<void> op) -> int

return 1;
}

#endif // BOOST_ASIO_HAS_CO_AWAIT
4 changes: 3 additions & 1 deletion test/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ auto redir(boost::system::error_code& ec)
auto start(boost::asio::awaitable<void> op) -> int;
#endif // BOOST_ASIO_HAS_CO_AWAIT

boost::redis::config make_test_config();

void
run(
std::shared_ptr<boost::redis::connection> conn,
boost::redis::config cfg = {},
boost::redis::config cfg = make_test_config(),
boost::system::error_code ec = boost::asio::error::operation_aborted,
boost::redis::operation op = boost::redis::operation::receive,
boost::redis::logger::level l = boost::redis::logger::level::disabled);
Expand Down
8 changes: 2 additions & 6 deletions test/test_conn_check_health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ using boost::redis::ignore;
using boost::redis::operation;
using boost::redis::generic_response;
using boost::redis::consume_one;
using redis::config;

// TODO: Test cancel(health_check)


struct push_callback {
connection* conn1;
connection* conn2;
Expand Down Expand Up @@ -73,14 +71,12 @@ struct push_callback {
BOOST_AUTO_TEST_CASE(check_health)
{
net::io_context ioc;


connection conn1{ioc};

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

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

config cfg2;
auto cfg2 = make_test_config();
cfg2.health_check_id = "conn2";
error_code res2;
conn2.async_run(cfg2, {}, [&](auto ec){
Expand Down
9 changes: 4 additions & 5 deletions test/test_conn_echo_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ using boost::redis::response;
using boost::redis::ignore;
using boost::redis::ignore_t;
using boost::redis::logger;
using boost::redis::config;
using boost::redis::connection;
using boost::redis::usage;
using boost::redis::error;
Expand Down Expand Up @@ -79,7 +78,7 @@ echo_session(
auto async_echo_stress(std::shared_ptr<connection> conn) -> net::awaitable<void>
{
auto ex = co_await net::this_coro::executor;
config cfg;
auto cfg = make_test_config();
cfg.health_check_interval = std::chrono::seconds::zero();
run(conn, cfg,
boost::asio::error::operation_aborted,
Expand All @@ -92,14 +91,14 @@ auto async_echo_stress(std::shared_ptr<connection> conn) -> net::awaitable<void>

// Number of coroutines that will send pings sharing the same
// connection to redis.
int const sessions = 1000;
int const sessions = 150;

// The number of pings that will be sent by each session.
int const msgs = 500;
int const msgs = 200;

// The number of publishes that will be sent by each session with
// each message.
int const n_pubs = 100;
int const n_pubs = 25;

// This is the total number of pushes we will receive.
int total_pushes = sessions * msgs * n_pubs + 1;
Expand Down
3 changes: 1 addition & 2 deletions test/test_conn_exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ using boost::redis::response;
using boost::redis::generic_response;
using boost::redis::ignore;
using boost::redis::operation;
using boost::redis::config;

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

BOOST_AUTO_TEST_CASE(correct_database)
{
config cfg;
auto cfg = make_test_config();
cfg.database_index = 2;

net::io_context ioc;
Expand Down
7 changes: 3 additions & 4 deletions test/test_conn_exec_cancel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ using boost::redis::response;
using boost::redis::generic_response;
using boost::redis::ignore;
using boost::redis::ignore_t;
using boost::redis::config;
using boost::redis::logger;
using boost::redis::connection;
using namespace std::chrono_literals;
Expand All @@ -39,8 +38,8 @@ auto implicit_cancel_of_req_written() -> net::awaitable<void>
auto ex = co_await net::this_coro::executor;
auto conn = std::make_shared<connection>(ex);

config cfg;
cfg.health_check_interval = std::chrono::seconds{0};
auto cfg = make_test_config();
cfg.health_check_interval = std::chrono::seconds::zero();
run(conn, cfg);

// See NOTE1.
Expand Down Expand Up @@ -106,7 +105,7 @@ BOOST_AUTO_TEST_CASE(test_cancel_of_req_written_on_run_canceled)

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

config cfg;
auto cfg = make_test_config();
cfg.health_check_interval = std::chrono::seconds{5};
run(conn);

Expand Down
1 change: 0 additions & 1 deletion test/test_conn_exec_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ using boost::redis::ignore_t;
using boost::redis::error;
using boost::redis::logger;
using boost::redis::operation;
using redis::config;
using namespace std::chrono_literals;

BOOST_AUTO_TEST_CASE(no_ignore_error)
Expand Down
4 changes: 2 additions & 2 deletions test/test_conn_exec_retry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(request_retry_false)

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

config cfg;
auto cfg = make_test_config();
cfg.health_check_interval = 5s;
run(conn);

Expand Down Expand Up @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(request_retry_true)

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

config cfg;
auto cfg = make_test_config();
cfg.health_check_interval = 5s;
conn->async_run(cfg, {}, [&](auto ec){
std::cout << ec.message() << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions test/test_conn_push.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ using boost::redis::response;
using boost::redis::ignore;
using boost::redis::ignore_t;
using boost::system::error_code;
using redis::config;
using boost::redis::logger;
using namespace std::chrono_literals;

Expand Down Expand Up @@ -67,7 +66,7 @@ BOOST_AUTO_TEST_CASE(receives_push_waiting_resps)

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

run(conn, {}, {});
run(conn, make_test_config(), {});

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

conn->async_run({}, {}, [](auto ec){
auto cfg = make_test_config();
conn->async_run(cfg, {}, [](auto ec){
BOOST_CHECK_EQUAL(ec, boost::redis::error::incompatible_size);
});

Expand Down Expand Up @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(many_subscribers)

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

run(conn, {}, {});
run(conn, make_test_config(), {});

net::co_spawn(ioc.get_executor(), push_consumer3(conn), net::detached);
ioc.run();
Expand Down
Loading

0 comments on commit 7caea92

Please sign in to comment.