Support ubuntu 18.04 (boost-1.65), and test it in CI.

This commit is contained in:
Tao He 2021-01-30 13:48:12 +08:00
parent 66c111b5ca
commit 692840cb58
6 changed files with 19 additions and 10 deletions

View File

@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-20.04, macos-10.15, macos-11.0] os: [ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0]
etcd: [v3.2.26, v3.3.11, v3.4.13] etcd: [v3.2.26, v3.3.11, v3.4.13]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View File

@ -61,8 +61,6 @@ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-string-compare -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-string-compare -std=c++11")
endif() endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
add_subdirectory(src) add_subdirectory(src)

View File

@ -9,7 +9,7 @@ i.e., `ETCDCTL_API=3`.
### Supported OS environments ### Supported OS environments
+ **Linux** + **Linux**
- Ubuntu 18.04, requires upgrade boost and grpc libraries. - Ubuntu 18.04, requires upgrade grpc libraries (has been tested with 1.27.x).
- Ubuntu 20.04 - Ubuntu 20.04
+ **MacOS** + **MacOS**
- MacOS 10.15 - MacOS 10.15

View File

@ -6,7 +6,12 @@
#include "etcd/Client.hpp" #include "etcd/Client.hpp"
#include "etcd/Response.hpp" #include "etcd/Response.hpp"
#include <boost/config.hpp>
#if BOOST_VERSION >= 106600
#include <boost/asio/io_context.hpp> #include <boost/asio/io_context.hpp>
#else
#include <boost/asio/io_service.hpp>
#endif
#include <boost/asio/steady_timer.hpp> #include <boost/asio/steady_timer.hpp>
#include <grpc++/grpc++.h> #include <grpc++/grpc++.h>
@ -55,7 +60,11 @@ namespace etcd
int ttl; int ttl;
int64_t lease_id; int64_t lease_id;
bool continue_next; bool continue_next;
#if BOOST_VERSION >= 106600
boost::asio::io_context context; boost::asio::io_context context;
#else
boost::asio::io_service context;
#endif
std::unique_ptr<boost::asio::steady_timer> keepalive_timer_; std::unique_ptr<boost::asio::steady_timer> keepalive_timer_;
}; };
} }

View File

@ -1,3 +1,5 @@
#include <chrono>
#include "etcd/KeepAlive.hpp" #include "etcd/KeepAlive.hpp"
#include "etcd/v3/AsyncLeaseAction.hpp" #include "etcd/v3/AsyncLeaseAction.hpp"
@ -70,7 +72,7 @@ void etcd::KeepAlive::refresh()
} }
#endif #endif
keepalive_timer_.reset(new boost::asio::steady_timer( keepalive_timer_.reset(new boost::asio::steady_timer(
context, boost::asio::chrono::seconds(keepalive_ttl))); context, std::chrono::seconds(keepalive_ttl)));
keepalive_timer_->async_wait([this](const boost::system::error_code& error) { keepalive_timer_->async_wait([this](const boost::system::error_code& error) {
if (error) { if (error) {
#ifndef NDEBUG #ifndef NDEBUG

View File

@ -32,17 +32,17 @@ TEST_CASE("create watcher with cancel")
watcher_called = 0; watcher_called = 0;
etcd::Watcher watcher(etcd_uri, "/test", printResponse, true); etcd::Watcher watcher(etcd_uri, "/test", printResponse, true);
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(3));
etcd.set("/test/key", "42"); etcd.set("/test/key", "42");
etcd.set("/test/key", "43"); etcd.set("/test/key", "43");
etcd.rm("/test/key"); etcd.rm("/test/key");
etcd.set("/test/key", "44"); etcd.set("/test/key", "44");
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(3));
CHECK(4 == watcher_called); CHECK(4 == watcher_called);
watcher.Cancel(); watcher.Cancel();
etcd.set("/test/key", "50"); etcd.set("/test/key", "50");
etcd.set("/test/key", "51"); etcd.set("/test/key", "51");
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(3));
CHECK(4 == watcher_called); CHECK(4 == watcher_called);
etcd.rmdir("/test", true); etcd.rmdir("/test", true);
@ -57,11 +57,11 @@ TEST_CASE("create watcher")
watcher_called = 0; watcher_called = 0;
{ {
etcd::Watcher watcher(etcd_uri, "/test", printResponse, true); etcd::Watcher watcher(etcd_uri, "/test", printResponse, true);
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(3));
etcd.set("/test/key", "42"); etcd.set("/test/key", "42");
etcd.set("/test/key", "43"); etcd.set("/test/key", "43");
std::this_thread::sleep_for(std::chrono::seconds(3));
} }
CHECK(2 == watcher_called); CHECK(2 == watcher_called);
etcd.rmdir("/test", true).error_code(); etcd.rmdir("/test", true).error_code();
} }