summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2024-01-31 17:05:21 +0100
committerRazvan Becheriu <razvan@isc.org>2024-03-05 08:50:05 +0100
commit8fc6b6f901cbf3827a68b07fa655ad64154a7319 (patch)
treeedd9f773cea46068e4d946ee546268110e0e46e2 /src
parent[#3190] use smart pointer to capture IOService instance (diff)
downloadkea-8fc6b6f901cbf3827a68b07fa655ad64154a7319.tar.xz
kea-8fc6b6f901cbf3827a68b07fa655ad64154a7319.zip
[#3190] fix ASAN warnings
Diffstat (limited to 'src')
-rw-r--r--src/lib/asiodns/tests/io_fetch_unittest.cc54
-rw-r--r--src/lib/asiolink/botan_boost_tls.h3
-rw-r--r--src/lib/asiolink/botan_tls.h3
-rw-r--r--src/lib/asiolink/common_tls.h6
-rw-r--r--src/lib/asiolink/interval_timer.cc3
-rw-r--r--src/lib/asiolink/interval_timer.h2
-rw-r--r--src/lib/asiolink/io_service.cc3
-rw-r--r--src/lib/asiolink/openssl_tls.h6
-rw-r--r--src/lib/asiolink/tests/interval_timer_unittest.cc33
-rw-r--r--src/lib/asiolink/tests/tcp_acceptor_unittest.cc24
-rw-r--r--src/lib/asiolink/tests/tls_acceptor_unittest.cc29
-rw-r--r--src/lib/asiolink/tests/tls_unittest.cc727
-rw-r--r--src/lib/asiolink/tests/unix_domain_socket_unittest.cc6
-rw-r--r--src/lib/asiolink/testutils/test_server_unix_socket.cc1
-rw-r--r--src/lib/asiolink/tls_acceptor.h3
-rw-r--r--src/lib/asiolink/udp_socket.h2
-rw-r--r--src/lib/config/cmd_http_listener.cc15
-rw-r--r--src/lib/config/tests/client_connection_unittests.cc74
-rw-r--r--src/lib/config/tests/cmd_http_listener_unittests.cc7
-rw-r--r--src/lib/d2srv/nc_trans.cc10
-rw-r--r--src/lib/d2srv/tests/dns_client_unittests.cc30
-rw-r--r--src/lib/d2srv/tests/nc_trans_unittests.cc511
-rw-r--r--src/lib/d2srv/testutils/nc_test_utils.cc13
-rw-r--r--src/lib/d2srv/testutils/nc_test_utils.h6
-rw-r--r--src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc14
-rw-r--r--src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc5
-rw-r--r--src/lib/dhcpsrv/tests/timer_mgr_unittest.cc5
-rw-r--r--src/lib/http/tests/client_mt_unittests.cc7
-rw-r--r--src/lib/http/tests/connection_pool_unittests.cc5
-rw-r--r--src/lib/http/tests/server_client_unittests.cc6
-rw-r--r--src/lib/http/tests/tls_client_unittests.cc10
-rw-r--r--src/lib/http/tests/tls_server_unittests.cc6
-rw-r--r--src/lib/process/d_controller.cc3
-rw-r--r--src/lib/tcp/mt_tcp_listener_mgr.cc13
-rw-r--r--src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc9
-rw-r--r--src/lib/tcp/tests/tcp_listener_unittests.cc7
-rw-r--r--src/lib/tcp/tests/tls_listener_unittests.cc7
37 files changed, 925 insertions, 743 deletions
diff --git a/src/lib/asiodns/tests/io_fetch_unittest.cc b/src/lib/asiodns/tests/io_fetch_unittest.cc
index 5bab99f6a3..59bbe566b7 100644
--- a/src/lib/asiodns/tests/io_fetch_unittest.cc
+++ b/src/lib/asiodns/tests/io_fetch_unittest.cc
@@ -85,6 +85,9 @@ public:
bool tcp_short_send_; ///< If set to true, we do not send
/// all data in the tcp response
+ boost::shared_ptr<udp::socket> udp_socket_;
+ boost::shared_ptr<tcp::socket> tcp_socket_;
+ boost::shared_ptr<tcp::acceptor> tcp_acceptor_;
/// \brief Constructor
IOFetchTest() :
@@ -139,7 +142,7 @@ public:
// the class.)
//
// We could initialize the data with a single character, but as an added
- // check we'll make ssre that it has some structure.
+ // check we'll make sure that it has some structure.
test_data_.clear();
test_data_.reserve(MAX_SIZE);
@@ -149,6 +152,14 @@ public:
}
}
+ virtual ~IOFetchTest() {
+ service_->restart();
+ try {
+ service_->poll();
+ } catch (...) {
+ }
+ }
+
/// \brief UDP Response handler (the "remote UDP DNS server")
///
/// When IOFetch is sending data, this response handler emulates the remote
@@ -343,7 +354,7 @@ public:
} else {
- // For all subsequent times, send the remainder, maximised to
+ // For all subsequent times, send the remainder, maximized to
// whatever we have chosen for the maximum send size.
amount = min(tcp_send_size_,
(send_buffer_.size() - send_cumulative_));
@@ -542,14 +553,15 @@ public:
}
// Socket into which the connection will be accepted.
- tcp::socket socket(service_->getInternalIOService());
+ tcp_socket_.reset(new tcp::socket(service_->getInternalIOService()));
// Acceptor object - called when the connection is made, the handler
// will initiate a read on the socket.
- tcp::acceptor acceptor(service_->getInternalIOService(),
- tcp::endpoint(tcp::v4(), TEST_PORT));
- acceptor.async_accept(socket,
- std::bind(&IOFetchTest::tcpAcceptHandler, this, &socket, ph::_1));
+ tcp_acceptor_.reset(new tcp::acceptor(service_->getInternalIOService(),
+ tcp::endpoint(tcp::v4(), TEST_PORT)));
+ tcp_acceptor_->async_accept(*tcp_socket_,
+ std::bind(&IOFetchTest::tcpAcceptHandler,
+ this, tcp_socket_.get(), ph::_1));
// Post the TCP fetch object to send the query and receive the response.
service_->post(tcp_fetch_);
@@ -557,10 +569,11 @@ public:
// ... and execute all the callbacks. This exits when the fetch
// completes.
service_->run();
- EXPECT_TRUE(run_); // Make sure the callback did execute
// Tidy up
- socket.close();
+ tcp_socket_->close();
+
+ EXPECT_TRUE(run_); // Make sure the callback did execute
}
/// Perform a send/receive test over UDP
@@ -574,18 +587,18 @@ public:
protocol_ = IOFetch::UDP;
// Set up the server.
- udp::socket socket(service_->getInternalIOService(), udp::v4());
- socket.set_option(socket_base::reuse_address(true));
- socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
+ udp_socket_.reset(new udp::socket(service_->getInternalIOService(), udp::v4()));
+ udp_socket_->set_option(socket_base::reuse_address(true));
+ udp_socket_->bind(udp::endpoint(TEST_HOST, TEST_PORT));
return_data_ = "Message returned to the client";
udp::endpoint remote;
- socket.async_receive_from(boost::asio::buffer(receive_buffer_,
- sizeof(receive_buffer_)),
- remote,
- std::bind(&IOFetchTest::udpReceiveHandler,
- this, &remote, &socket,
- ph::_1, ph::_2, bad_qid, second_send));
+ udp_socket_->async_receive_from(boost::asio::buffer(receive_buffer_,
+ sizeof(receive_buffer_)),
+ remote,
+ std::bind(&IOFetchTest::udpReceiveHandler,
+ this, &remote, udp_socket_.get(),
+ ph::_1, ph::_2, bad_qid, second_send));
service_->post(udp_fetch_);
if (debug_) {
cout << "udpSendReceive: async_receive_from posted,"
@@ -593,9 +606,10 @@ public:
}
service_->run();
- socket.close();
+ // Tidy up
+ udp_socket_->close();
- EXPECT_TRUE(run_);
+ EXPECT_TRUE(run_); // Make sure the callback did execute
}
};
diff --git a/src/lib/asiolink/botan_boost_tls.h b/src/lib/asiolink/botan_boost_tls.h
index 5c74d2702a..c9bff8dc1b 100644
--- a/src/lib/asiolink/botan_boost_tls.h
+++ b/src/lib/asiolink/botan_boost_tls.h
@@ -108,7 +108,8 @@ typedef Botan::TLS::Stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
template <typename Callback, typename TlsStreamImpl>
TlsStreamBase<Callback, TlsStreamImpl>::
TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
- : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
+ : StreamService(io_service, context),
+ TlsStreamImpl(io_service->getInternalIOService(),
context->getContext()), role_(context->getRole()) {
}
diff --git a/src/lib/asiolink/botan_tls.h b/src/lib/asiolink/botan_tls.h
index df0ad33767..affee89c03 100644
--- a/src/lib/asiolink/botan_tls.h
+++ b/src/lib/asiolink/botan_tls.h
@@ -96,7 +96,8 @@ typedef boost::asio::ip::tcp::socket TlsStreamImpl;
template <typename Callback, typename TlsStreamImpl>
TlsStreamBase<Callback, TlsStreamImpl>::
TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
- : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService()),
+ : StreamService(io_service, context),
+ TlsStreamImpl(io_service->getInternalIOService()),
role_(context->getRole()) {
}
diff --git a/src/lib/asiolink/common_tls.h b/src/lib/asiolink/common_tls.h
index 87306d9171..72db172301 100644
--- a/src/lib/asiolink/common_tls.h
+++ b/src/lib/asiolink/common_tls.h
@@ -121,11 +121,15 @@ public:
class StreamService {
public:
/// @brief Constructor.
- StreamService(const IOServicePtr& io_service) : io_service_(io_service) {
+ StreamService(const IOServicePtr& io_service, TlsContextPtr& tls_context) :
+ io_service_(io_service), tls_context_(tls_context) {
}
private:
/// @brief The IO service used to handle events.
IOServicePtr io_service_;
+
+ /// @brief OpenSSL TLS context.
+ TlsContextPtr tls_context_;
};
/// @brief TLS stream base class.
diff --git a/src/lib/asiolink/interval_timer.cc b/src/lib/asiolink/interval_timer.cc
index 6226bf1e28..21480b0316 100644
--- a/src/lib/asiolink/interval_timer.cc
+++ b/src/lib/asiolink/interval_timer.cc
@@ -51,8 +51,7 @@ public:
/// @param interval The interval used to start the timer.
/// @param interval_mode The interval mode used by the timer.
void setup(const IntervalTimer::Callback& cbfunc, const long interval,
- const IntervalTimer::Mode& interval_mode
- = IntervalTimer::REPEATING);
+ const IntervalTimer::Mode& interval_mode = IntervalTimer::REPEATING);
/// @brief Callback function which calls the registerd callback.
///
diff --git a/src/lib/asiolink/interval_timer.h b/src/lib/asiolink/interval_timer.h
index 0475abcadc..98b189191e 100644
--- a/src/lib/asiolink/interval_timer.h
+++ b/src/lib/asiolink/interval_timer.h
@@ -111,7 +111,7 @@ public:
/// \throw isc::BadValue interval is less than or equal to 0
/// \throw isc::Unexpected internal runtime error
void setup(const Callback& cbfunc, const long interval,
- const Mode& mode = REPEATING);
+ const Mode& mode = REPEATING);
/// Cancel the timer.
///
diff --git a/src/lib/asiolink/io_service.cc b/src/lib/asiolink/io_service.cc
index d0204df308..92044b6829 100644
--- a/src/lib/asiolink/io_service.cc
+++ b/src/lib/asiolink/io_service.cc
@@ -29,7 +29,8 @@ public:
};
/// \brief The destructor.
- ~IOServiceImpl() {};
+ ~IOServiceImpl() {
+ };
//@}
/// \brief Start the underlying event loop.
diff --git a/src/lib/asiolink/openssl_tls.h b/src/lib/asiolink/openssl_tls.h
index 957d9e5ad2..6a9112aedb 100644
--- a/src/lib/asiolink/openssl_tls.h
+++ b/src/lib/asiolink/openssl_tls.h
@@ -118,7 +118,8 @@ typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
template <typename Callback, typename TlsStreamImpl>
TlsStreamBase<Callback, TlsStreamImpl>::
TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
- : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
+ : StreamService(io_service, context),
+ TlsStreamImpl(io_service->getInternalIOService(),
context->getContext()), role_(context->getRole()) {
}
@@ -142,7 +143,8 @@ public:
}
/// @brief Destructor.
- virtual ~TlsStream() { }
+ virtual ~TlsStream() {
+ }
/// @brief TLS Handshake.
///
diff --git a/src/lib/asiolink/tests/interval_timer_unittest.cc b/src/lib/asiolink/tests/interval_timer_unittest.cc
index b2cd459ac1..6efd5951d2 100644
--- a/src/lib/asiolink/tests/interval_timer_unittest.cc
+++ b/src/lib/asiolink/tests/interval_timer_unittest.cc
@@ -25,16 +25,22 @@ using namespace isc::asiolink;
class IntervalTimerTest : public ::testing::Test {
protected:
IntervalTimerTest() :
- io_service_(new IOService()), timer_called_(false), timer_cancel_success_(false)
- {}
- ~IntervalTimerTest() {}
+ io_service_(new IOService()), timer_called_(false),
+ timer_cancel_success_(false) {
+ }
+ ~IntervalTimerTest() {
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
+ }
class TimerCallBack {
public:
TimerCallBack(IntervalTimerTest* test_obj) : test_obj_(test_obj) {}
void operator()() const {
test_obj_->timer_called_ = true;
test_obj_->io_service_->stop();
- return;
}
private:
IntervalTimerTest* test_obj_;
@@ -42,13 +48,11 @@ protected:
class TimerCallBackCounter {
public:
TimerCallBackCounter(IntervalTimerTest* test_obj) :
- test_obj_(test_obj)
- {
+ test_obj_(test_obj) {
counter_ = 0;
}
void operator()() {
++counter_;
- return;
}
int counter_;
private:
@@ -60,8 +64,8 @@ protected:
IntervalTimer* timer,
TimerCallBackCounter& counter)
: test_obj_(test_obj), timer_(timer), counter_(counter), count_(0),
- prev_counter_(-1)
- {}
+ prev_counter_(-1) {
+ }
void operator()() {
++count_;
if (count_ == 1) {
@@ -80,7 +84,6 @@ protected:
test_obj_->timer_cancel_success_ = true;
}
}
- return;
}
private:
IntervalTimerTest* test_obj_;
@@ -92,8 +95,8 @@ protected:
class TimerCallBackCanceller {
public:
TimerCallBackCanceller(unsigned int& counter, IntervalTimer& itimer) :
- counter_(counter), itimer_(itimer)
- {}
+ counter_(counter), itimer_(itimer) {
+ }
void operator()() {
++counter_;
itimer_.cancel();
@@ -106,8 +109,8 @@ protected:
public:
TimerCallBackOverwriter(IntervalTimerTest* test_obj,
IntervalTimer& timer)
- : test_obj_(test_obj), timer_(timer), count_(0)
- {}
+ : test_obj_(test_obj), timer_(timer), count_(0) {
+ }
void operator()() {
++count_;
if (count_ == 1) {
@@ -121,7 +124,6 @@ protected:
// We should stop here.
test_obj_->io_service_->stop();
}
- return;
}
private:
IntervalTimerTest* test_obj_;
@@ -135,7 +137,6 @@ protected:
}
void operator()() {
++counter_;
- return;
}
private:
IntervalTimerTest* test_obj_;
diff --git a/src/lib/asiolink/tests/tcp_acceptor_unittest.cc b/src/lib/asiolink/tests/tcp_acceptor_unittest.cc
index 5ca4eebcd3..08e025dcfa 100644
--- a/src/lib/asiolink/tests/tcp_acceptor_unittest.cc
+++ b/src/lib/asiolink/tests/tcp_acceptor_unittest.cc
@@ -64,8 +64,9 @@ public:
/// connect() to connect to the server.
///
/// @param io_service IO service to be stopped on error.
- explicit TCPClient(const IOServicePtr& io_service)
- : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
+ explicit TCPClient(const IOServicePtr& io_service, bool& running)
+ : io_service_(io_service), socket_(io_service_->getInternalIOService()),
+ running_(running) {
}
/// @brief Destructor.
@@ -94,6 +95,9 @@ public:
///
/// @param ec Error code.
void connectHandler(const boost::system::error_code& ec) {
+ if (!running_) {
+ return;
+ }
if (ec) {
// One would expect that async_connect wouldn't return EINPROGRESS
// error code, but simply wait for the connection to get
@@ -123,6 +127,8 @@ private:
/// @brief A socket used for the connection.
boost::asio::ip::tcp::socket socket_;
+ /// @brief Flag which indicates if the test is still running.
+ bool& running_;
};
/// @brief Pointer to the TCPClient.
@@ -206,13 +212,20 @@ public:
SERVER_PORT),
endpoint_(asio_endpoint_), test_timer_(io_service_), connections_(),
clients_(), connections_num_(0), aborted_connections_num_(0),
- max_connections_(1) {
+ max_connections_(1), running_(true) {
test_timer_.setup(std::bind(&TCPAcceptorTest::timeoutHandler, this),
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
}
/// @brief Destructor.
virtual ~TCPAcceptorTest() {
+ running_ = false;
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Specifies how many new connections are expected before the IO
@@ -264,7 +277,7 @@ public:
/// This method creates TCPClient instance and retains it in the clients_
/// list.
void connect() {
- TCPClientPtr client(new TCPClient(io_service_));
+ TCPClientPtr client(new TCPClient(io_service_, running_));
clients_.push_back(client);
clients_.back()->connect();
}
@@ -333,6 +346,9 @@ public:
/// @brief Connections limit.
unsigned int max_connections_;
+
+ /// @brief Flag which indicates if the test is still running.
+ bool running_;
};
// Test TCPAcceptor::asyncAccept.
diff --git a/src/lib/asiolink/tests/tls_acceptor_unittest.cc b/src/lib/asiolink/tests/tls_acceptor_unittest.cc
index d042566839..323f1fd4cd 100644
--- a/src/lib/asiolink/tests/tls_acceptor_unittest.cc
+++ b/src/lib/asiolink/tests/tls_acceptor_unittest.cc
@@ -65,8 +65,9 @@ public:
/// connect() to connect to the server.
///
/// @param io_service IO service to be stopped on error.
- explicit TLSClient(const IOServicePtr& io_service)
- : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
+ explicit TLSClient(const IOServicePtr& io_service, bool& running)
+ : io_service_(io_service), socket_(io_service_->getInternalIOService()),
+ running_(running) {
}
/// @brief Destructor.
@@ -95,6 +96,9 @@ public:
///
/// @param ec Error code.
void connectHandler(const boost::system::error_code& ec) {
+ if (!running_) {
+ return;
+ }
if (ec) {
// One would expect that async_connect wouldn't return EINPROGRESS
// error code, but simply wait for the connection to get
@@ -124,6 +128,8 @@ private:
/// @brief A socket used for the connection.
ip::tcp::socket socket_;
+ /// @brief Flag which indicates if the test is still running.
+ bool& running_;
};
/// @brief Pointer to the TLSClient.
@@ -154,8 +160,8 @@ public:
TlsContextPtr context,
TestTLSAcceptor& acceptor,
const TLSAcceptorCallback& callback)
- : io_service_(io_service), socket_(io_service_, context), acceptor_(acceptor),
- callback_(callback) {
+ : io_service_(io_service), socket_(io_service_, context),
+ acceptor_(acceptor), callback_(callback) {
}
/// @brief Destructor.
@@ -188,7 +194,6 @@ private:
/// @brief Instance of the callback used for asyncAccept.
TLSAcceptorCallback callback_;
-
};
/// @brief Pointer to the Acceptor object.
@@ -214,13 +219,20 @@ public:
SERVER_PORT),
endpoint_(asio_endpoint_), test_timer_(io_service_), connections_(),
clients_(), connections_num_(0), aborted_connections_num_(0),
- max_connections_(1) {
+ max_connections_(1), running_(true) {
test_timer_.setup(std::bind(&TLSAcceptorTest::timeoutHandler, this),
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
}
/// @brief Destructor.
virtual ~TLSAcceptorTest() {
+ running_ = false;
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Specifies how many new connections are expected before the IO
@@ -273,7 +285,7 @@ public:
/// This method creates TLSClient instance and retains it in the clients_
/// list.
void connect() {
- TLSClientPtr client(new TLSClient(io_service_));
+ TLSClientPtr client(new TLSClient(io_service_, running_));
clients_.push_back(client);
clients_.back()->connect();
}
@@ -342,6 +354,9 @@ public:
/// @brief Connections limit.
unsigned int max_connections_;
+
+ /// @brief Flag which indicates if the test is still running.
+ bool running_;
};
// Test TLSAcceptor::asyncAccept.
diff --git a/src/lib/asiolink/tests/tls_unittest.cc b/src/lib/asiolink/tests/tls_unittest.cc
index f57b9a47e3..e26c487807 100644
--- a/src/lib/asiolink/tests/tls_unittest.cc
+++ b/src/lib/asiolink/tests/tls_unittest.cc
@@ -408,24 +408,58 @@ public:
};
+/// @brief Test fixture class for TlsContext.
+class TLSTest : public ::testing::Test {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// Besides initializing class members it also sets the test timer to guard
+ /// against endlessly running IO service when TCP connections are
+ /// unsuccessful.
+ TLSTest() : io_service_(new IOService()) {
+ }
+
+ /// @brief Destructor.
+ virtual ~TLSTest() {
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
+ }
+
+ /// @brief IO service.
+ IOServicePtr io_service_;
+
+ /// @brief The shutdown callback.
+ TestCallback shutdown_cb_;
+
+ /// @brief The TLS server.
+ boost::shared_ptr<TlsStream<TestCallback>> server_;
+
+ /// @brief The TLS client.
+ boost::shared_ptr<TlsStream<TestCallback>> client_;
+};
+
////////////////////////////////////////////////////////////////////////
// TlsContext tests //
////////////////////////////////////////////////////////////////////////
// Test if we can get a client context.
-TEST(TLSTest, clientContext) {
+TEST_F(TLSTest, clientContext) {
TlsContextPtr ctx;
EXPECT_NO_THROW(ctx.reset(new TlsContext(TlsRole::CLIENT)));
}
// Test if we can get a server context.
-TEST(TLSTest, serverContext) {
+TEST_F(TLSTest, serverContext) {
TlsContextPtr ctx;
EXPECT_NO_THROW(ctx.reset(new TlsContext(TlsRole::SERVER)));
}
// Test if the cert required flag is handled as expected.
-TEST(TLSTest, certRequired) {
+TEST_F(TLSTest, certRequired) {
auto check = [] (TlsContext& ctx) -> bool {
#ifdef WITH_BOTAN
return (ctx.getCertRequired());
@@ -469,14 +503,14 @@ TEST(TLSTest, certRequired) {
}
// Test if the certificate authority can be loaded.
-TEST(TLSTest, loadCAFile) {
+TEST_F(TLSTest, loadCAFile) {
string ca(string(TEST_CA_DIR) + "/kea-ca.crt");
TestTlsContext ctx(TlsRole::CLIENT);
EXPECT_NO_THROW(ctx.loadCaFile(ca));
}
// Test that no certificate authority gives an error.
-TEST(TLSTest, loadNoCAFile) {
+TEST_F(TLSTest, loadNoCAFile) {
Expecteds exps;
// Botan error.
exps.addThrow("I/O error: DataSource: Failure opening file /no-such-file");
@@ -498,7 +532,7 @@ TEST(TLSTest, loadNoCAFile) {
// Test that Botan requires a real CA certificate so fails with
// trusted self-signed client.
/// @note: convert to GTEST when gtest_utils.h will be moved.
-TEST(TLSTest, loadTrustedSelfCAFile) {
+TEST_F(TLSTest, loadTrustedSelfCAFile) {
Expecteds exps;
// Botan error.
string botan_error = "Flatfile_Certificate_Store received non CA cert ";
@@ -517,14 +551,14 @@ TEST(TLSTest, loadTrustedSelfCAFile) {
#endif // WITH_BOTAN
// Test that a directory can be loaded.
-TEST(TLSTest, loadCAPath) {
+TEST_F(TLSTest, loadCAPath) {
string ca(TEST_CA_DIR);
TestTlsContext ctx(TlsRole::CLIENT);
EXPECT_NO_THROW(ctx.loadCaPath(ca));
}
// Test that a certificate is wanted.
-TEST(TLSTest, loadKeyCA) {
+TEST_F(TLSTest, loadKeyCA) {
Expecteds exps;
// Botan error.
exps.addThrow("Flatfile_Certificate_Store::Flatfile_Certificate_Store cert file is empty");
@@ -546,14 +580,14 @@ TEST(TLSTest, loadKeyCA) {
}
// Test if the end entity certificate can be loaded.
-TEST(TLSTest, loadCertFile) {
+TEST_F(TLSTest, loadCertFile) {
string cert(string(TEST_CA_DIR) + "/kea-client.crt");
TestTlsContext ctx(TlsRole::CLIENT);
EXPECT_NO_THROW(ctx.loadCertFile(cert));
}
// Test that no end entity certificate gives an error.
-TEST(TLSTest, loadNoCertFile) {
+TEST_F(TLSTest, loadNoCertFile) {
Expecteds exps;
// Botan error.
exps.addThrow("I/O error: DataSource: Failure opening file /no-such-file");
@@ -572,7 +606,7 @@ TEST(TLSTest, loadNoCertFile) {
}
// Test that a certificate is wanted.
-TEST(TLSTest, loadCsrCertFile) {
+TEST_F(TLSTest, loadCsrCertFile) {
Expecteds exps;
// Botan error.
exps.addThrow("Expected a certificate, got 'CERTIFICATE REQUEST'");
@@ -592,14 +626,14 @@ TEST(TLSTest, loadCsrCertFile) {
}
// Test if the private key can be loaded.
-TEST(TLSTest, loadKeyFile) {
+TEST_F(TLSTest, loadKeyFile) {
string key(string(TEST_CA_DIR) + "/kea-client.key");
TestTlsContext ctx(TlsRole::CLIENT);
EXPECT_NO_THROW(ctx.loadKeyFile(key));
}
// Test that no private key gives an error.
-TEST(TLSTest, loadNoKeyFile) {
+TEST_F(TLSTest, loadNoKeyFile) {
Expecteds exps;
// Botan error.
exps.addThrow("I/O error: DataSource: Failure opening file /no-such-file");
@@ -620,7 +654,7 @@ TEST(TLSTest, loadNoKeyFile) {
}
// Test that a private key is wanted.
-TEST(TLSTest, loadCertKeyFile) {
+TEST_F(TLSTest, loadCertKeyFile) {
Expecteds exps;
// Botan error.
string botan_error = "PKCS #8 private key decoding failed with PKCS #8: ";
@@ -648,7 +682,7 @@ TEST(TLSTest, loadCertKeyFile) {
}
// Test that the certificate and private key must match.
-TEST(TLSTest, loadMismatch) {
+TEST_F(TLSTest, loadMismatch) {
Expecteds exps;
exps.addNoError();
exps.runCanThrow([] {
@@ -672,7 +706,7 @@ TEST(TLSTest, loadMismatch) {
}
// Test the configure class method.
-TEST(TLSTest, configure) {
+TEST_F(TLSTest, configure) {
TlsContextPtr ctx;
string ca(string(TEST_CA_DIR) + "/kea-ca.crt");
string cert(string(TEST_CA_DIR) + "/kea-client.crt");
@@ -696,7 +730,7 @@ TEST(TLSTest, configure) {
}
// Test the configure class method error case.
-TEST(TLSTest, configureError) {
+TEST_F(TLSTest, configureError) {
// The error case.
Expecteds exps;
// Common part of the error message.
@@ -729,43 +763,40 @@ TEST(TLSTest, configureError) {
////////////////////////////////////////////////////////////////////////
// Test if we can get a stream.
-TEST(TLSTest, stream) {
- IOServicePtr service(new IOService());
+TEST_F(TLSTest, stream) {
TlsContextPtr ctx(new TlsContext(TlsRole::CLIENT));
boost::scoped_ptr<TlsStream<TestCallback> > st;
- EXPECT_NO_THROW(st.reset(new TlsStream<TestCallback>(service, ctx)));
+ EXPECT_NO_THROW(server_.reset(new TlsStream<TestCallback>(io_service_, ctx)));
}
// Test what happens when handshake is forgotten.
-TEST(TLSTest, noHandshake) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, noHandshake) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -781,16 +812,16 @@ TEST(TLSTest, noHandshake) {
}
// Setup a timeout.
- IntervalTimer timer1(service);
+ IntervalTimer timer1(io_service_);
bool timeout = false;
timer1.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Send on the client.
char send_buf[] = "some text...";
TestCallback send_cb;
- async_write(client, boost::asio::buffer(send_buf), send_cb);
+ async_write(*client_, boost::asio::buffer(send_buf), send_cb);
while (!timeout && !send_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
timer1.cancel();
@@ -808,16 +839,16 @@ TEST(TLSTest, noHandshake) {
}
// Setup a second timeout.
- IntervalTimer timer2(service);
+ IntervalTimer timer2(io_service_);
timeout = false;
timer2.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Receive on the server.
vector<char> receive_buf(64);
TestCallback receive_cb;
- server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
+ server_->async_read_some(boost::asio::buffer(receive_buf), receive_cb);
while (!timeout && !receive_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
timer2.cancel();
@@ -839,40 +870,38 @@ TEST(TLSTest, noHandshake) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the server was not configured.
-TEST(TLSTest, serverNotConfigured) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, serverNotConfigured) {
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Skip config.
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -888,17 +917,17 @@ TEST(TLSTest, serverNotConfigured) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.handshake(server_cb);
+ server_->handshake(server_cb);
TestCallback client_cb;
- client.handshake(client_cb);
+ client_->handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -939,40 +968,38 @@ TEST(TLSTest, serverNotConfigured) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client was not configured.
-TEST(TLSTest, clientNotConfigured) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, clientNotConfigured) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx(new TlsContext(TlsRole::CLIENT));
// Skip config.
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -988,17 +1015,17 @@ TEST(TLSTest, clientNotConfigured) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1038,29 +1065,27 @@ TEST(TLSTest, clientNotConfigured) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client is HTTP (vs HTTPS).
-TEST(TLSTest, clientHTTPnoS) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, clientHTTPnoS) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
- tcp::socket client(service->getInternalIOService());
+ tcp::socket client(io_service_->getInternalIOService());
// Connect to.
client.open(tcp::v4());
@@ -1069,7 +1094,7 @@ TEST(TLSTest, clientHTTPnoS) {
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1085,13 +1110,13 @@ TEST(TLSTest, clientHTTPnoS) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform server TLS handshake.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
// Client sending a HTTP GET.
char send_buf[] = "GET / HTTP/1.1\r\n";
@@ -1099,7 +1124,7 @@ TEST(TLSTest, clientHTTPnoS) {
client.async_send(boost::asio::buffer(send_buf), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1134,28 +1159,26 @@ TEST(TLSTest, clientHTTPnoS) {
// Close client and server.
EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client does not use HTTP nor HTTP.
-TEST(TLSTest, unknownClient) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, unknownClient) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
- tcp::socket client(service->getInternalIOService());
+ tcp::socket client(io_service_->getInternalIOService());
// Connect to.
client.open(tcp::v4());
@@ -1164,7 +1187,7 @@ TEST(TLSTest, unknownClient) {
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1180,13 +1203,13 @@ TEST(TLSTest, unknownClient) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform server TLS handshake.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
// Client sending something which is not a TLS ClientHello.
char send_buf[] = "hello my server...";
@@ -1194,7 +1217,7 @@ TEST(TLSTest, unknownClient) {
client.async_send(boost::asio::buffer(send_buf), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1225,39 +1248,37 @@ TEST(TLSTest, unknownClient) {
// Close client and server.
EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client uses a certificate from another CA.
-TEST(TLSTest, anotherClient) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, anotherClient) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part using a certificate signed by another CA.
TlsContextPtr client_ctx;
test::configOther(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1273,17 +1294,17 @@ TEST(TLSTest, anotherClient) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1325,40 +1346,38 @@ TEST(TLSTest, anotherClient) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client uses a self-signed certificate.
-TEST(TLSTest, selfSigned) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, selfSigned) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part using a self-signed certificate.
TlsContextPtr client_ctx;
test::configSelf(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1374,17 +1393,17 @@ TEST(TLSTest, selfSigned) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1426,8 +1445,8 @@ TEST(TLSTest, selfSigned) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
////////////////////////////////////////////////////////////////////////
@@ -1439,35 +1458,33 @@ TEST(TLSTest, selfSigned) {
// the other peer timeout?
// Test what happens when handshake is forgotten.
-TEST(TLSTest, noHandshakeCloseonError) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, noHandshakeCloseonError) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1483,16 +1500,16 @@ TEST(TLSTest, noHandshakeCloseonError) {
}
// Setup a timeout.
- IntervalTimer timer1(service);
+ IntervalTimer timer1(io_service_);
bool timeout = false;
timer1.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Send on the client.
char send_buf[] = "some text...";
- TestCallback send_cb(&client.lowest_layer());
- async_write(client, boost::asio::buffer(send_buf), send_cb);
+ TestCallback send_cb(&client_->lowest_layer());
+ async_write(*client_, boost::asio::buffer(send_buf), send_cb);
while (!timeout && !send_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
timer1.cancel();
@@ -1510,16 +1527,16 @@ TEST(TLSTest, noHandshakeCloseonError) {
}
// Setup a second timeout.
- IntervalTimer timer2(service);
+ IntervalTimer timer2(io_service_);
timeout = false;
timer2.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Receive on the server.
vector<char> receive_buf(64);
TestCallback receive_cb;
- server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
+ server_->async_read_some(boost::asio::buffer(receive_buf), receive_cb);
while (!timeout && !receive_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
timer2.cancel();
@@ -1537,40 +1554,38 @@ TEST(TLSTest, noHandshakeCloseonError) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the server was not configured.
-TEST(TLSTest, serverNotConfiguredCloseonError) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, serverNotConfiguredCloseonError) {
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Skip config.
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1586,17 +1601,17 @@ TEST(TLSTest, serverNotConfiguredCloseonError) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
- TestCallback server_cb(&server.lowest_layer());
- server.handshake(server_cb);
+ TestCallback server_cb(&server_->lowest_layer());
+ server_->handshake(server_cb);
TestCallback client_cb;
- client.handshake(client_cb);
+ client_->handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1636,40 +1651,38 @@ TEST(TLSTest, serverNotConfiguredCloseonError) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client was not configured.
-TEST(TLSTest, clientNotConfiguredCloseonError) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, clientNotConfiguredCloseonError) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx(new TlsContext(TlsRole::CLIENT));
// Skip config.
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1685,17 +1698,17 @@ TEST(TLSTest, clientNotConfiguredCloseonError) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
- TestCallback client_cb(&client.lowest_layer());
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ TestCallback client_cb(&client_->lowest_layer());
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1734,29 +1747,27 @@ TEST(TLSTest, clientNotConfiguredCloseonError) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client is HTTP (vs HTTPS).
-TEST(TLSTest, clientHTTPnoSCloseonError) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, clientHTTPnoSCloseonError) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
- tcp::socket client(service->getInternalIOService());
+ tcp::socket client(io_service_->getInternalIOService());
// Connect to.
client.open(tcp::v4());
@@ -1765,7 +1776,7 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1781,13 +1792,13 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform server TLS handshake.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
// Client sending a HTTP GET.
char send_buf[] = "GET / HTTP/1.1\r\n";
@@ -1795,7 +1806,7 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
client.async_send(boost::asio::buffer(send_buf), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1830,39 +1841,37 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
// Close client and server.
EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client uses a certificate from another CA.
-TEST(TLSTest, anotherClientCloseonError) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, anotherClientCloseonError) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part using a certificate signed by another CA.
TlsContextPtr client_ctx;
test::configOther(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1878,17 +1887,17 @@ TEST(TLSTest, anotherClientCloseonError) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
- TestCallback server_cb(&server.lowest_layer());
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ TestCallback server_cb(&server_->lowest_layer());
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -1928,40 +1937,38 @@ TEST(TLSTest, anotherClientCloseonError) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the client uses a self-signed certificate.
-TEST(TLSTest, selfSignedCloseonError) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, selfSignedCloseonError) {
// Server part.
TlsContextPtr server_ctx;
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part using a self-signed certificate.
TlsContextPtr client_ctx;
test::configSelf(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -1977,17 +1984,17 @@ TEST(TLSTest, selfSignedCloseonError) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
- TestCallback server_cb(&server.lowest_layer());
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ TestCallback server_cb(&server_->lowest_layer());
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2027,8 +2034,8 @@ TEST(TLSTest, selfSignedCloseonError) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
////////////////////////////////////////////////////////////////////////
@@ -2039,35 +2046,33 @@ TEST(TLSTest, selfSignedCloseonError) {
// Test what happens when the client uses a certificate from another CA
// but the client certificate request and validation are disabled.
-TEST(TLSTest, anotherClientNoReq) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, anotherClientNoReq) {
// Server part.
TlsContextPtr server_ctx;
test::configServerNoReq(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part using a certificate signed by another CA.
TlsContextPtr client_ctx;
test::configOther(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -2083,17 +2088,17 @@ TEST(TLSTest, anotherClientNoReq) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2105,41 +2110,39 @@ TEST(TLSTest, anotherClientNoReq) {
EXPECT_FALSE(client_cb.getCode());
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the server uses a certificate without subject
// alternative name (but still a version 3 certificate).
-TEST(TLSTest, serverRaw) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, serverRaw) {
// Server part.
TlsContextPtr server_ctx;
test::configServerRaw(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -2155,17 +2158,17 @@ TEST(TLSTest, serverRaw) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2177,42 +2180,40 @@ TEST(TLSTest, serverRaw) {
EXPECT_FALSE(client_cb.getCode());
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
#ifdef WITH_OPENSSL
// Test what happens when the client uses a trusted self-signed certificate.
// Not really a failure case as it works...
-TEST(TLSTest, trustedSelfSigned) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, trustedSelfSigned) {
// Server part.
TlsContextPtr server_ctx;
test::configTrustedSelf(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part using a self-signed certificate.
TlsContextPtr client_ctx;
test::configSelf(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -2228,17 +2229,17 @@ TEST(TLSTest, trustedSelfSigned) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
TestCallback server_cb;
- server.async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
+ server_->async_handshake(roleToImpl(TlsRole::SERVER), server_cb);
TestCallback client_cb;
- client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
+ client_->async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2250,8 +2251,8 @@ TEST(TLSTest, trustedSelfSigned) {
EXPECT_FALSE(client_cb.getCode());
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
#endif // WITH_OPENSSL
@@ -2262,35 +2263,33 @@ TEST(TLSTest, trustedSelfSigned) {
// Investigate the TLS shutdown processing.
// Test what happens when the shutdown receiver is inactive.
-TEST(TLSTest, shutdownInactive) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, shutdownInactive) {
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -2306,17 +2305,17 @@ TEST(TLSTest, shutdownInactive) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
- TestCallback server_cb(&server.lowest_layer());
- server.handshake(server_cb);
+ TestCallback server_cb(&server_->lowest_layer());
+ server_->handshake(server_cb);
TestCallback client_cb;
- client.handshake(client_cb);
+ client_->handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2328,15 +2327,14 @@ TEST(TLSTest, shutdownInactive) {
EXPECT_FALSE(client_cb.getCode());
// Setup a timeout for the shutdown.
- IntervalTimer timer2(service);
+ IntervalTimer timer2(io_service_);
timeout = false;
timer2.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Shutdown on the client leaving the server inactive.
- TestCallback shutdown_cb;
- client.shutdown(shutdown_cb);
- while (!timeout && !shutdown_cb.getCalled()) {
- service->runOne();
+ client_->shutdown(shutdown_cb_);
+ while (!timeout && !shutdown_cb_.getCalled()) {
+ io_service_->runOne();
}
timer2.cancel();
@@ -2345,7 +2343,7 @@ TEST(TLSTest, shutdownInactive) {
exps.addNoError();
// OpenSSL hangs.
exps.addTimeout();
- exps.checkAsync("shutdown", shutdown_cb);
+ exps.checkAsync("shutdown", shutdown_cb_);
if (Expecteds::displayErrMsg()) {
if (timeout) {
std::cout << "shutdown timeout\n";
@@ -2355,40 +2353,38 @@ TEST(TLSTest, shutdownInactive) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the shutdown receiver is active.
-TEST(TLSTest, shutdownActive) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, shutdownActive) {
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -2404,17 +2400,17 @@ TEST(TLSTest, shutdownActive) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
- TestCallback server_cb(&server.lowest_layer());
- server.handshake(server_cb);
+ TestCallback server_cb(&server_->lowest_layer());
+ server_->handshake(server_cb);
TestCallback client_cb;
- client.handshake(client_cb);
+ client_->handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2426,20 +2422,19 @@ TEST(TLSTest, shutdownActive) {
EXPECT_FALSE(client_cb.getCode());
// Setup a timeout for the shutdown and receive.
- IntervalTimer timer2(service);
+ IntervalTimer timer2(io_service_);
timeout = false;
timer2.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Receive on the server.
vector<char> receive_buf(64);
TestCallback receive_cb;
- server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
+ server_->async_read_some(boost::asio::buffer(receive_buf), receive_cb);
// Shutdown on the client.
- TestCallback shutdown_cb;
- client.shutdown(shutdown_cb);
- while (!timeout && (!shutdown_cb.getCalled() || !receive_cb.getCalled())) {
- service->runOne();
+ client_->shutdown(shutdown_cb_);
+ while (!timeout && (!shutdown_cb_.getCalled() || !receive_cb.getCalled())) {
+ io_service_->runOne();
}
timer2.cancel();
@@ -2448,7 +2443,7 @@ TEST(TLSTest, shutdownActive) {
exps.addNoError();
// OpenSSL hangs.
exps.addTimeout();
- exps.checkAsync("shutdown", shutdown_cb);
+ exps.checkAsync("shutdown", shutdown_cb_);
if (Expecteds::displayErrMsg()) {
if (timeout) {
std::cout << "shutdown timeout\n";
@@ -2466,41 +2461,39 @@ TEST(TLSTest, shutdownActive) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the shutdown receiver is inactive on shutdown
// and immediate close.
-TEST(TLSTest, shutdownCloseInactive) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, shutdownCloseInactive) {
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -2516,17 +2509,17 @@ TEST(TLSTest, shutdownCloseInactive) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
- TestCallback server_cb(&server.lowest_layer());
- server.handshake(server_cb);
+ TestCallback server_cb(&server_->lowest_layer());
+ server_->handshake(server_cb);
TestCallback client_cb;
- client.handshake(client_cb);
+ client_->handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2538,18 +2531,17 @@ TEST(TLSTest, shutdownCloseInactive) {
EXPECT_FALSE(client_cb.getCode());
// Setup a timeout for the shutdown.
- IntervalTimer timer2(service);
+ IntervalTimer timer2(io_service_);
timeout = false;
timer2.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Shutdown on the client leaving the server inactive.
- TestCallback shutdown_cb;
- client.shutdown(shutdown_cb);
+ client_->shutdown(shutdown_cb_);
// Post a close which should be called after the shutdown.
- service->post([&client] { client.lowest_layer().close(); });
- while (!timeout && !shutdown_cb.getCalled()) {
- service->runOne();
+ io_service_->post([&] { client_->lowest_layer().close(); });
+ while (!timeout && !shutdown_cb_.getCalled()) {
+ io_service_->runOne();
}
timer2.cancel();
@@ -2560,7 +2552,7 @@ TEST(TLSTest, shutdownCloseInactive) {
exps.addError("Operation canceled");
// OpenSSL gets Bad file descriptor.
exps.addError("Bad file descriptor");
- exps.checkAsync("shutdown", shutdown_cb);
+ exps.checkAsync("shutdown", shutdown_cb_);
if (Expecteds::displayErrMsg()) {
if (timeout) {
std::cout << "shutdown timeout\n";
@@ -2570,41 +2562,39 @@ TEST(TLSTest, shutdownCloseInactive) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Test what happens when the shutdown receiver is active with an
// immediate close.
-TEST(TLSTest, shutdownCloseActive) {
- IOServicePtr service(new IOService());
-
+TEST_F(TLSTest, shutdownCloseActive) {
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
test::configServer(server_ctx);
- TlsStream<TestCallback> server(service, server_ctx);
+ server_.reset(new TlsStream<TestCallback>(io_service_, server_ctx));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(io_service_->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
- acceptor.async_accept(server.lowest_layer(), accept_cb);
+ acceptor.async_accept(server_->lowest_layer(), accept_cb);
// Client part.
TlsContextPtr client_ctx;
test::configClient(client_ctx);
- TlsStream<TestCallback> client(service, client_ctx);
+ client_.reset(new TlsStream<TestCallback>(io_service_, client_ctx));
// Connect to.
- client.lowest_layer().open(tcp::v4());
+ client_->lowest_layer().open(tcp::v4());
TestCallback connect_cb;
- client.lowest_layer().async_connect(server_ep, connect_cb);
+ client_->lowest_layer().async_connect(server_ep, connect_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service->runOne();
+ io_service_->runOne();
}
// Verify the error codes.
@@ -2620,17 +2610,17 @@ TEST(TLSTest, shutdownCloseActive) {
}
// Setup a timeout.
- IntervalTimer timer(service);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Perform TLS handshakes.
- TestCallback server_cb(&server.lowest_layer());
- server.handshake(server_cb);
+ TestCallback server_cb(&server_->lowest_layer());
+ server_->handshake(server_cb);
TestCallback client_cb;
- client.handshake(client_cb);
+ client_->handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service->runOne();
+ io_service_->runOne();
}
timer.cancel();
@@ -2642,23 +2632,22 @@ TEST(TLSTest, shutdownCloseActive) {
EXPECT_FALSE(client_cb.getCode());
// Setup a timeout for the shutdown and receive.
- IntervalTimer timer2(service);
+ IntervalTimer timer2(io_service_);
timeout = false;
timer2.setup([&timeout] { timeout = true; }, 100, IntervalTimer::ONE_SHOT);
// Receive on the server.
vector<char> receive_buf(64);
TestCallback receive_cb;
- server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
+ server_->async_read_some(boost::asio::buffer(receive_buf), receive_cb);
// Shutdown on the client.
- TestCallback shutdown_cb;
- client.shutdown(shutdown_cb);
+ client_->shutdown(shutdown_cb_);
// Post a close which should be called after the shutdown.
- service->post([&client] { client.lowest_layer().close(); });
- while (!timeout && (!shutdown_cb.getCalled() || !receive_cb.getCalled())) {
- service->runOne();
+ io_service_->post([&] { client_->lowest_layer().close(); });
+ while (!timeout && (!shutdown_cb_.getCalled() || !receive_cb.getCalled())) {
+ io_service_->runOne();
}
timer2.cancel();
@@ -2669,7 +2658,7 @@ TEST(TLSTest, shutdownCloseActive) {
exps.addError("Operation canceled");
// OpenSSL gets Bad file descriptor.
exps.addError("Bad file descriptor");
- exps.checkAsync("shutdown", shutdown_cb);
+ exps.checkAsync("shutdown", shutdown_cb_);
if (Expecteds::displayErrMsg()) {
if (timeout) {
std::cout << "shutdown timeout\n";
@@ -2687,8 +2676,8 @@ TEST(TLSTest, shutdownCloseActive) {
}
// Close client and server.
- EXPECT_NO_THROW(client.lowest_layer().close());
- EXPECT_NO_THROW(server.lowest_layer().close());
+ EXPECT_NO_THROW(client_->lowest_layer().close());
+ EXPECT_NO_THROW(server_->lowest_layer().close());
}
// Conclusion about the shutdown: do the close on completion (e.g. in the
diff --git a/src/lib/asiolink/tests/unix_domain_socket_unittest.cc b/src/lib/asiolink/tests/unix_domain_socket_unittest.cc
index b237d0cf13..2dd42cb87d 100644
--- a/src/lib/asiolink/tests/unix_domain_socket_unittest.cc
+++ b/src/lib/asiolink/tests/unix_domain_socket_unittest.cc
@@ -47,6 +47,12 @@ public:
/// Removes unix socket descriptor after the test.
virtual ~UnixDomainSocketTest() {
removeUnixSocketFile();
+ test_socket_.reset();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Returns socket file path.
diff --git a/src/lib/asiolink/testutils/test_server_unix_socket.cc b/src/lib/asiolink/testutils/test_server_unix_socket.cc
index 9df24be1b2..7fccc49991 100644
--- a/src/lib/asiolink/testutils/test_server_unix_socket.cc
+++ b/src/lib/asiolink/testutils/test_server_unix_socket.cc
@@ -236,6 +236,7 @@ TestServerUnixSocket::TestServerUnixSocket(const IOServicePtr& io_service,
}
TestServerUnixSocket::~TestServerUnixSocket() {
+ test_timer_.cancel();
server_acceptor_.close();
}
diff --git a/src/lib/asiolink/tls_acceptor.h b/src/lib/asiolink/tls_acceptor.h
index 1acac5ce3d..368dbda875 100644
--- a/src/lib/asiolink/tls_acceptor.h
+++ b/src/lib/asiolink/tls_acceptor.h
@@ -38,7 +38,8 @@ public:
}
/// @brief Destructor.
- virtual ~TLSAcceptor() { }
+ virtual ~TLSAcceptor() {
+ }
/// @brief Asynchronously accept new connection.
///
diff --git a/src/lib/asiolink/udp_socket.h b/src/lib/asiolink/udp_socket.h
index 68adb351d8..17afd28085 100644
--- a/src/lib/asiolink/udp_socket.h
+++ b/src/lib/asiolink/udp_socket.h
@@ -79,7 +79,7 @@ public:
///
/// Indicates that the opening of a UDP socket is synchronous.
virtual bool isOpenSynchronous() const {
- return true;
+ return (true);
}
/// \brief Open Socket
diff --git a/src/lib/config/cmd_http_listener.cc b/src/lib/config/cmd_http_listener.cc
index e02f65eec0..66dc705e10 100644
--- a/src/lib/config/cmd_http_listener.cc
+++ b/src/lib/config/cmd_http_listener.cc
@@ -81,9 +81,14 @@ CmdHttpListener::start() {
.arg(port_)
.arg(tls_context_ ? "true" : "false");
} catch (const std::exception& ex) {
- thread_io_service_.reset();
- http_listener_.reset();
thread_pool_.reset();
+ http_listener_.reset();
+ thread_io_service_->restart();
+ try {
+ thread_io_service_->poll();
+ } catch(...) {
+ }
+ thread_io_service_.reset();
isc_throw(Unexpected, "CmdHttpListener::run failed: " << ex.what());
}
}
@@ -126,6 +131,12 @@ CmdHttpListener::stop() {
// Get rid of the listener.
http_listener_.reset();
+ thread_io_service_->restart();
+ try {
+ thread_io_service_->poll();
+ } catch(...) {
+ }
+
// Ditch the IOService.
thread_io_service_.reset();
diff --git a/src/lib/config/tests/client_connection_unittests.cc b/src/lib/config/tests/client_connection_unittests.cc
index 38597ce810..702bef316d 100644
--- a/src/lib/config/tests/client_connection_unittests.cc
+++ b/src/lib/config/tests/client_connection_unittests.cc
@@ -33,7 +33,7 @@ public:
///
/// Removes unix socket descriptor before the test.
ClientConnectionTest() :
- io_service_(new IOService()),
+ io_service_(new IOService()), handler_invoked_(false),
test_socket_(new test::TestServerUnixSocket(io_service_,
unixSocketFilePath())) {
removeUnixSocketFile();
@@ -44,6 +44,13 @@ public:
/// Removes unix socket descriptor after the test.
virtual ~ClientConnectionTest() {
removeUnixSocketFile();
+ conn_.reset();
+ test_socket_.reset();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Returns socket file path.
@@ -78,8 +85,14 @@ public:
/// @brief IO service used by the tests.
IOServicePtr io_service_;
+ /// @brief Flag which indicates if the callback has been called.
+ bool handler_invoked_;
+
/// @brief Server side unix socket used in these tests.
test::TestServerUnixSocketPtr test_socket_;
+
+ /// @brief Client connection.
+ ClientConnectionPtr conn_;
};
// Tests successful transaction: connect, send command and receive a
@@ -95,18 +108,18 @@ TEST_F(ClientConnectionTest, success) {
// Create some valid command.
std::string command = "{ \"command\": \"list-commands\" }";
- ClientConnection conn(io_service_);
+ conn_.reset(new ClientConnection(io_service_));
- // This boolean value will indicate when the callback function is invoked
- // at the end of the transaction (whether it is successful or unsuccessful).
- bool handler_invoked = false;
- conn.start(ClientConnection::SocketPath(unixSocketFilePath()),
- ClientConnection::ControlCommand(command),
- [&handler_invoked](const boost::system::error_code& ec,
- const ConstJSONFeedPtr& feed) {
+ conn_->start(ClientConnection::SocketPath(unixSocketFilePath()),
+ ClientConnection::ControlCommand(command),
+ [&](const boost::system::error_code& ec,
+ const ConstJSONFeedPtr& feed) {
+ if (handler_invoked_) {
+ return;
+ }
// Indicate that the handler has been called to break from the
// while loop below.
- handler_invoked = true;
+ handler_invoked_ = true;
// The ec should contain no error.
ASSERT_FALSE(ec);
// The JSONFeed should be present and it should contain a valid
@@ -115,7 +128,7 @@ TEST_F(ClientConnectionTest, success) {
EXPECT_TRUE(feed->feedOk()) << feed->getErrorMessage();
});
// Run the connection.
- while (!handler_invoked && !test_socket_->isStopped()) {
+ while (!handler_invoked_ && !test_socket_->isStopped()) {
io_service_->runOne();
}
}
@@ -137,24 +150,27 @@ TEST_F(ClientConnectionTest, timeout) {
// Command to be sent to the server.
std::string command = "{ \"command\": \"list-commands\" }";
- ClientConnection conn(io_service_);
+ conn_.reset(new ClientConnection(io_service_));
- // This boolean value will be set to true when the callback is invoked.
- bool handler_invoked = false;
- conn.start(ClientConnection::SocketPath(unixSocketFilePath()),
- ClientConnection::ControlCommand(command),
- [&handler_invoked](const boost::system::error_code& ec,
- const ConstJSONFeedPtr& /*feed*/) {
+ conn_->start(ClientConnection::SocketPath(unixSocketFilePath()),
+ ClientConnection::ControlCommand(command),
+ [&](const boost::system::error_code& ec,
+ const ConstJSONFeedPtr& /*feed*/) {
+ if (handler_invoked_) {
+ return;
+ }
// Indicate that the callback has been invoked to break the loop
// below.
- handler_invoked = true;
+ handler_invoked_ = true;
ASSERT_TRUE(ec);
EXPECT_TRUE(ec.value() == boost::asio::error::timed_out);
}, ClientConnection::Timeout(1000));
- while (!handler_invoked && !test_socket_->isStopped()) {
+ while (!handler_invoked_ && !test_socket_->isStopped()) {
io_service_->runOne();
}
+
+ test_socket_->stopServer();
}
// This test checks that an error is returned when the client is unable
@@ -162,20 +178,22 @@ TEST_F(ClientConnectionTest, timeout) {
TEST_F(ClientConnectionTest, connectionError) {
// Create the new connection but do not bind the server socket.
// The connection should be refused and an error returned.
- ClientConnection conn(io_service_);
+ conn_.reset(new ClientConnection(io_service_));
std::string command = "{ \"command\": \"list-commands\" }";
- bool handler_invoked = false;
- conn.start(ClientConnection::SocketPath(unixSocketFilePath()),
- ClientConnection::ControlCommand(command),
- [&handler_invoked](const boost::system::error_code& ec,
- const ConstJSONFeedPtr& /*feed*/) {
- handler_invoked = true;
+ conn_->start(ClientConnection::SocketPath(unixSocketFilePath()),
+ ClientConnection::ControlCommand(command),
+ [&](const boost::system::error_code& ec,
+ const ConstJSONFeedPtr& /*feed*/) {
+ if (handler_invoked_) {
+ return;
+ }
+ handler_invoked_ = true;
ASSERT_TRUE(ec);
});
- while (!handler_invoked && !test_socket_->isStopped()) {
+ while (!handler_invoked_ && !test_socket_->isStopped()) {
io_service_->runOne();
}
}
diff --git a/src/lib/config/tests/cmd_http_listener_unittests.cc b/src/lib/config/tests/cmd_http_listener_unittests.cc
index fbb5c8ac79..1362928c1b 100644
--- a/src/lib/config/tests/cmd_http_listener_unittests.cc
+++ b/src/lib/config/tests/cmd_http_listener_unittests.cc
@@ -80,6 +80,13 @@ public:
client->close();
}
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
+
// Deregisters commands.
config::CommandMgr::instance().deregisterAll();
diff --git a/src/lib/d2srv/nc_trans.cc b/src/lib/d2srv/nc_trans.cc
index e9adce5432..edfd3fdaa7 100644
--- a/src/lib/d2srv/nc_trans.cc
+++ b/src/lib/d2srv/nc_trans.cc
@@ -71,11 +71,11 @@ NameChangeTransaction(asiolink::IOServicePtr& io_service,
DdnsDomainPtr& reverse_domain,
D2CfgMgrPtr& cfg_mgr)
: io_service_(io_service), ncr_(ncr), forward_domain_(forward_domain),
- reverse_domain_(reverse_domain), dns_client_(), dns_update_request_(),
- dns_update_status_(DNSClient::OTHER), dns_update_response_(),
- forward_change_completed_(false), reverse_change_completed_(false),
- current_server_list_(), current_server_(), next_server_pos_(0),
- update_attempts_(0), cfg_mgr_(cfg_mgr), tsig_key_() {
+ reverse_domain_(reverse_domain), dns_client_(), dns_update_request_(),
+ dns_update_status_(DNSClient::OTHER), dns_update_response_(),
+ forward_change_completed_(false), reverse_change_completed_(false),
+ current_server_list_(), current_server_(), next_server_pos_(0),
+ update_attempts_(0), cfg_mgr_(cfg_mgr), tsig_key_() {
/// @todo if io_service is NULL we are multi-threading and should
/// instantiate our own
if (!io_service_) {
diff --git a/src/lib/d2srv/tests/dns_client_unittests.cc b/src/lib/d2srv/tests/dns_client_unittests.cc
index 9ffe0963e1..4ec19cd484 100644
--- a/src/lib/d2srv/tests/dns_client_unittests.cc
+++ b/src/lib/d2srv/tests/dns_client_unittests.cc
@@ -11,6 +11,7 @@
#include <asiodns/io_fetch.h>
#include <asiodns/logger.h>
#include <asiolink/interval_timer.h>
+#include <d2srv/d2_update_message.h>
#include <d2srv/testutils/nc_test_utils.h>
#include <d2srv/testutils/stats_test_utils.h>
#include <dns/messagerenderer.h>
@@ -124,6 +125,12 @@ public:
///
/// Sets the asiodns logging level back to DEBUG.
virtual ~DNSClientTest() {
+ test_timer_.cancel();
+ service_->restart();
+ try {
+ service_->poll();
+ } catch (...) {
+ }
asiodns::logger.setSeverity(isc::log::DEBUG);
};
@@ -311,21 +318,19 @@ public:
/// @brief This test verifies that it accepted timeout values belong to the
/// range of <0, DNSClient::getMaxTimeout()>.
void runInvalidTimeoutTest() {
-
expect_response_ = false;
- // Create outgoing message. Simply set the required message fields:
+ // Create inbound message. Simply set the required message fields:
// error code and Zone section. This is enough to create on-wire format
// of this message and send it.
- D2UpdateMessage message(D2UpdateMessage::OUTBOUND);
- ASSERT_NO_THROW(message.setRcode(Rcode(Rcode::NOERROR_CODE)));
- ASSERT_NO_THROW(message.setZone(Name("example.com"), RRClass::IN()));
+ D2UpdateMessage message(D2UpdateMessage::INBOUND);
// Start with a valid timeout equal to maximal allowed. This way we will
// ensure that doUpdate doesn't throw an exception for valid timeouts.
unsigned int timeout = DNSClient::getMaxTimeout();
- EXPECT_NO_THROW(dns_client_->doUpdate(service_, IOAddress(TEST_ADDRESS),
- TEST_PORT, message, timeout));
+ EXPECT_THROW(dns_client_->doUpdate(service_, IOAddress(TEST_ADDRESS),
+ TEST_PORT, message, timeout),
+ isc::d2::InvalidZoneSection);
// Cross the limit and expect that exception is thrown this time.
timeout = DNSClient::getMaxTimeout() + 1;
@@ -368,7 +373,6 @@ public:
// This starts the execution of tasks posted to IOService. run() blocks
// until stop() is called in the completion callback function.
service_->run();
-
}
/// @brief This test verifies that DNSClient can send DNS Update and receive
@@ -435,7 +439,7 @@ public:
}
- // Kick of the message exchange by actually running the scheduled
+ // Kick off the message exchange by actually running the scheduled
// "send" and "receive" operations.
service_->run();
@@ -445,6 +449,10 @@ public:
// we must reset it in order for subsequent calls to run() or
// runOne() to work.
service_->restart();
+ try {
+ service_->poll();
+ } catch (...) {
+ }
}
/// @brief Performs a single request-response exchange with or without TSIG.
@@ -497,6 +505,10 @@ public:
// we must reset it in order for subsequent calls to run() or
// runOne() to work.
service_->restart();
+ try {
+ service_->poll();
+ } catch (...) {
+ }
}
};
diff --git a/src/lib/d2srv/tests/nc_trans_unittests.cc b/src/lib/d2srv/tests/nc_trans_unittests.cc
index e1df8e27e6..9bd52c3d81 100644
--- a/src/lib/d2srv/tests/nc_trans_unittests.cc
+++ b/src/lib/d2srv/tests/nc_trans_unittests.cc
@@ -22,6 +22,7 @@
using namespace std;
using namespace isc;
+using namespace isc::asiolink;
using namespace isc::d2;
using namespace isc::util;
using namespace boost::posix_time;
@@ -272,13 +273,22 @@ typedef boost::shared_ptr<NameChangeStub> NameChangeStubPtr;
class NameChangeTransactionTest : public TransactionTest {
public:
NameChangeTransactionTest() {
+ io_service_.reset(new IOService());
+ timer_.reset(new IntervalTimer(io_service_));
}
virtual ~NameChangeTransactionTest() {
+ timer_->cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
+ io_service_.reset(new IOService());
+ timer_.reset(new IntervalTimer(io_service_));
}
-
- /// @brief Instantiates a NameChangeStub test transaction
+ /// @brief Instantiates a NameChangeStub test transaction
/// The transaction is constructed around a predefined (i.e "canned")
/// NameChangeRequest. The request has both forward and reverse DNS
/// changes requested, and both forward and reverse domains are populated.
@@ -296,7 +306,7 @@ public:
forward_domain_, reverse_domain_, cfg_mgr_)));
}
- /// @brief Instantiates a NameChangeStub test transaction
+ /// @brief Instantiates a NameChangeStub test transaction
/// The transaction is constructed around a predefined (i.e "canned")
/// NameChangeRequest. The request has both forward and reverse DNS
/// changes requested, and both forward and reverse domains are populated.
@@ -349,6 +359,10 @@ public:
}
}
}
+
+ boost::shared_ptr<FauxServer> server_;
+
+ NameChangeStubPtr name_change_;
};
/// @brief Tests NameChangeTransaction construction.
@@ -359,8 +373,7 @@ public:
/// 3. Construction with null reverse domain is not allowed when the request
/// requires reverse change.
/// 4. Valid construction functions properly
-TEST(NameChangeTransaction, construction) {
- asiolink::IOServicePtr io_service(new isc::asiolink::IOService());
+TEST_F(NameChangeTransactionTest, construction) {
D2CfgMgrPtr cfg_mgr(new D2CfgMgr());
const char* msg_str =
@@ -396,32 +409,31 @@ TEST(NameChangeTransaction, construction) {
NameChangeTransactionError);
// Verify that construction with an empty NameChangeRequest throws.
- EXPECT_THROW(NameChangeTransaction(io_service, empty_ncr,
+ EXPECT_THROW(NameChangeTransaction(io_service_, empty_ncr,
forward_domain, reverse_domain, cfg_mgr),
- NameChangeTransactionError);
+ NameChangeTransactionError);
// Verify that construction with an empty D2CfgMgr throws.
D2CfgMgrPtr empty_cfg;
- EXPECT_THROW(NameChangeTransaction(io_service, empty_ncr,
+ EXPECT_THROW(NameChangeTransaction(io_service_, empty_ncr,
forward_domain, reverse_domain,
empty_cfg),
NameChangeTransactionError);
-
// Verify that construction with an empty forward domain when the
// NameChangeRequest calls for a forward change throws.
- EXPECT_THROW(NameChangeTransaction(io_service, ncr,
+ EXPECT_THROW(NameChangeTransaction(io_service_, ncr,
empty_domain, reverse_domain, cfg_mgr),
NameChangeTransactionError);
// Verify that construction with an empty reverse domain when the
// NameChangeRequest calls for a reverse change throws.
- EXPECT_THROW(NameChangeTransaction(io_service, ncr,
+ EXPECT_THROW(NameChangeTransaction(io_service_, ncr,
forward_domain, empty_domain, cfg_mgr),
NameChangeTransactionError);
// Verify that a valid construction attempt works.
- EXPECT_NO_THROW(NameChangeTransaction(io_service, ncr,
+ EXPECT_NO_THROW(NameChangeTransaction(io_service_, ncr,
forward_domain, reverse_domain,
cfg_mgr));
@@ -429,7 +441,7 @@ TEST(NameChangeTransaction, construction) {
// not include a forward change.
ncr->setForwardChange(false);
ncr->setReverseChange(true);
- EXPECT_NO_THROW(NameChangeTransaction(io_service, ncr,
+ EXPECT_NO_THROW(NameChangeTransaction(io_service_, ncr,
empty_domain, reverse_domain,
cfg_mgr));
@@ -437,7 +449,7 @@ TEST(NameChangeTransaction, construction) {
// not include a reverse change.
ncr->setForwardChange(true);
ncr->setReverseChange(false);
- EXPECT_NO_THROW(NameChangeTransaction(io_service, ncr,
+ EXPECT_NO_THROW(NameChangeTransaction(io_service_, ncr,
forward_domain, empty_domain,
cfg_mgr));
}
@@ -445,198 +457,192 @@ TEST(NameChangeTransaction, construction) {
/// @brief General testing of member accessors.
/// Most if not all of these are also tested as a byproduct of larger tests.
TEST_F(NameChangeTransactionTest, accessors) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Verify that fetching the NameChangeRequest works.
- dhcp_ddns::NameChangeRequestPtr ncr = name_change->getNcr();
+ dhcp_ddns::NameChangeRequestPtr ncr = name_change_->getNcr();
ASSERT_TRUE(ncr);
// Verify that getTransactionKey works.
- EXPECT_EQ(ncr->getDhcid(), name_change->getTransactionKey());
+ EXPECT_EQ(ncr->getDhcid(), name_change_->getTransactionKey());
// Verify that getRequestId works.
- EXPECT_EQ(ncr->getRequestId(), name_change->getRequestId());
+ EXPECT_EQ(ncr->getRequestId(), name_change_->getRequestId());
// Verify that NcrStatus can be set and retrieved.
- EXPECT_NO_THROW(name_change->setNcrStatus(dhcp_ddns::ST_FAILED));
+ EXPECT_NO_THROW(name_change_->setNcrStatus(dhcp_ddns::ST_FAILED));
EXPECT_EQ(dhcp_ddns::ST_FAILED, ncr->getStatus());
// Verify that the forward domain can be retrieved.
- ASSERT_TRUE(name_change->getForwardDomain());
- EXPECT_EQ(forward_domain_, name_change->getForwardDomain());
+ ASSERT_TRUE(name_change_->getForwardDomain());
+ EXPECT_EQ(forward_domain_, name_change_->getForwardDomain());
// Verify that the reverse domain can be retrieved.
- ASSERT_TRUE(name_change->getReverseDomain());
- EXPECT_EQ(reverse_domain_, name_change->getReverseDomain());
+ ASSERT_TRUE(name_change_->getReverseDomain());
+ EXPECT_EQ(reverse_domain_, name_change_->getReverseDomain());
// Neither of these have direct setters, but are tested under server
// selection.
- EXPECT_FALSE(name_change->getDNSClient());
- EXPECT_FALSE(name_change->getCurrentServer());
+ EXPECT_FALSE(name_change_->getDNSClient());
+ EXPECT_FALSE(name_change_->getCurrentServer());
// Verify that DNS update status can be set and retrieved.
- EXPECT_NO_THROW(name_change->setDnsUpdateStatus(DNSClient::TIMEOUT));
- EXPECT_EQ(DNSClient::TIMEOUT, name_change->getDnsUpdateStatus());
+ EXPECT_NO_THROW(name_change_->setDnsUpdateStatus(DNSClient::TIMEOUT));
+ EXPECT_EQ(DNSClient::TIMEOUT, name_change_->getDnsUpdateStatus());
// Verify that the forward change complete flag can be set and fetched.
- EXPECT_NO_THROW(name_change->setForwardChangeCompleted(true));
- EXPECT_TRUE(name_change->getForwardChangeCompleted());
+ EXPECT_NO_THROW(name_change_->setForwardChangeCompleted(true));
+ EXPECT_TRUE(name_change_->getForwardChangeCompleted());
// Verify that the reverse change complete flag can be set and fetched.
- EXPECT_NO_THROW(name_change->setReverseChangeCompleted(true));
- EXPECT_TRUE(name_change->getReverseChangeCompleted());
+ EXPECT_NO_THROW(name_change_->setReverseChangeCompleted(true));
+ EXPECT_TRUE(name_change_->getReverseChangeCompleted());
}
/// @brief Tests DNS update request accessor methods.
TEST_F(NameChangeTransactionTest, dnsUpdateRequestAccessors) {
// Create a transaction.
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Post transaction construction, there should not be an update request.
- EXPECT_FALSE(name_change->getDnsUpdateRequest());
+ EXPECT_FALSE(name_change_->getDnsUpdateRequest());
// Create a request.
D2UpdateMessagePtr req;
ASSERT_NO_THROW(req.reset(new D2UpdateMessage(D2UpdateMessage::OUTBOUND)));
// Use the setter and then verify we can fetch the request.
- ASSERT_NO_THROW(name_change->setDnsUpdateRequest(req));
+ ASSERT_NO_THROW(name_change_->setDnsUpdateRequest(req));
// Post set, we should be able to fetch it.
- ASSERT_TRUE(name_change->getDnsUpdateRequest());
+ ASSERT_TRUE(name_change_->getDnsUpdateRequest());
// Should be able to clear it.
- ASSERT_NO_THROW(name_change->clearDnsUpdateRequest());
+ ASSERT_NO_THROW(name_change_->clearDnsUpdateRequest());
// Should be empty again.
- EXPECT_FALSE(name_change->getDnsUpdateRequest());
+ EXPECT_FALSE(name_change_->getDnsUpdateRequest());
}
/// @brief Tests DNS update request accessor methods.
TEST_F(NameChangeTransactionTest, dnsUpdateResponseAccessors) {
// Create a transaction.
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Post transaction construction, there should not be an update response.
- EXPECT_FALSE(name_change->getDnsUpdateResponse());
+ EXPECT_FALSE(name_change_->getDnsUpdateResponse());
// Create a response.
D2UpdateMessagePtr resp;
ASSERT_NO_THROW(resp.reset(new D2UpdateMessage(D2UpdateMessage::INBOUND)));
// Use the setter and then verify we can fetch the response.
- ASSERT_NO_THROW(name_change->setDnsUpdateResponse(resp));
+ ASSERT_NO_THROW(name_change_->setDnsUpdateResponse(resp));
// Post set, we should be able to fetch it.
- EXPECT_TRUE(name_change->getDnsUpdateResponse());
+ EXPECT_TRUE(name_change_->getDnsUpdateResponse());
// Should be able to clear it.
- ASSERT_NO_THROW(name_change->clearDnsUpdateResponse());
+ ASSERT_NO_THROW(name_change_->clearDnsUpdateResponse());
// Should be empty again.
- EXPECT_FALSE(name_change->getDnsUpdateResponse());
+ EXPECT_FALSE(name_change_->getDnsUpdateResponse());
}
/// @brief Tests responseString method.
TEST_F(NameChangeTransactionTest, responseString) {
// Create a transaction.
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Make sure it is safe to call when status says success but there
// is no update response.
- ASSERT_NO_THROW(name_change->setDnsUpdateStatus(DNSClient::SUCCESS));
+ ASSERT_NO_THROW(name_change_->setDnsUpdateStatus(DNSClient::SUCCESS));
EXPECT_EQ("SUCCESS, rcode: update response is NULL",
- name_change->responseString());
+ name_change_->responseString());
// Create a response. (We use an OUTBOUND message so we can set RCODE)
D2UpdateMessagePtr resp;
ASSERT_NO_THROW(resp.reset(new D2UpdateMessage(D2UpdateMessage::OUTBOUND)));
- ASSERT_NO_THROW(name_change->setDnsUpdateResponse(resp));
+ ASSERT_NO_THROW(name_change_->setDnsUpdateResponse(resp));
// Make sure we decode Rcode when status is successful.
ASSERT_NO_THROW(resp->setRcode(dns::Rcode::NXDOMAIN()));
- EXPECT_EQ("SUCCESS, rcode: NXDOMAIN", name_change->responseString());
+ EXPECT_EQ("SUCCESS, rcode: NXDOMAIN", name_change_->responseString());
// Test all of the non-success values for status.
- ASSERT_NO_THROW(name_change->setDnsUpdateStatus(DNSClient::TIMEOUT));
- EXPECT_EQ("TIMEOUT", name_change->responseString());
+ ASSERT_NO_THROW(name_change_->setDnsUpdateStatus(DNSClient::TIMEOUT));
+ EXPECT_EQ("TIMEOUT", name_change_->responseString());
- ASSERT_NO_THROW(name_change->setDnsUpdateStatus(DNSClient::IO_STOPPED));
- EXPECT_EQ("IO_STOPPED", name_change->responseString());
+ ASSERT_NO_THROW(name_change_->setDnsUpdateStatus(DNSClient::IO_STOPPED));
+ EXPECT_EQ("IO_STOPPED", name_change_->responseString());
- ASSERT_NO_THROW(name_change->setDnsUpdateStatus(DNSClient::
+ ASSERT_NO_THROW(name_change_->setDnsUpdateStatus(DNSClient::
INVALID_RESPONSE));
- EXPECT_EQ("INVALID_RESPONSE", name_change->responseString());
+ EXPECT_EQ("INVALID_RESPONSE", name_change_->responseString());
- ASSERT_NO_THROW(name_change->setDnsUpdateStatus(DNSClient::OTHER));
- EXPECT_EQ("OTHER", name_change->responseString());
+ ASSERT_NO_THROW(name_change_->setDnsUpdateStatus(DNSClient::OTHER));
+ EXPECT_EQ("OTHER", name_change_->responseString());
}
/// @brief Tests transactionOutcomeString method.
TEST_F(NameChangeTransactionTest, transactionOutcomeString) {
// Create a transaction.
- NameChangeStubPtr name_change;
dhcp_ddns::NameChangeRequestPtr ncr;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ncr = name_change->getNcr();
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ncr = name_change_->getNcr();
// Check case of failed transaction in both directions
std::string exp_str("Status: Failed, Event: UNDEFINED, Forward change:"
" failed, Reverse change: failed, request: ");
exp_str += ncr->toText();
- std::string tstring = name_change->transactionOutcomeString();
+ std::string tstring = name_change_->transactionOutcomeString();
std::cout << "tstring is: [" << tstring << "]" << std::endl;
- EXPECT_EQ(exp_str, name_change->transactionOutcomeString());
+ EXPECT_EQ(exp_str, name_change_->transactionOutcomeString());
// Check case of success all around
- name_change->setNcrStatus(dhcp_ddns::ST_COMPLETED);
- name_change->setForwardChangeCompleted(true);
- name_change->setReverseChangeCompleted(true);
+ name_change_->setNcrStatus(dhcp_ddns::ST_COMPLETED);
+ name_change_->setForwardChangeCompleted(true);
+ name_change_->setReverseChangeCompleted(true);
exp_str = "Status: Completed, Event: UNDEFINED, Forward change: completed,"
" Reverse change: completed, request: " + ncr->toText();
- EXPECT_EQ(exp_str, name_change->transactionOutcomeString());
+ EXPECT_EQ(exp_str, name_change_->transactionOutcomeString());
// Check case of success, with no forward change
- name_change->setNcrStatus(dhcp_ddns::ST_COMPLETED);
+ name_change_->setNcrStatus(dhcp_ddns::ST_COMPLETED);
ncr->setForwardChange(false);
exp_str = "Status: Completed, Event: UNDEFINED, "
" Reverse change: completed, request: " + ncr->toText();
- EXPECT_EQ(exp_str, name_change->transactionOutcomeString());
+ EXPECT_EQ(exp_str, name_change_->transactionOutcomeString());
// Check case of success, with no reverse change
- name_change->setNcrStatus(dhcp_ddns::ST_COMPLETED);
+ name_change_->setNcrStatus(dhcp_ddns::ST_COMPLETED);
ncr->setForwardChange(true);
ncr->setReverseChange(false);
exp_str = "Status: Completed, Event: UNDEFINED, "
" Forward change: completed, request: " + ncr->toText();
- EXPECT_EQ(exp_str, name_change->transactionOutcomeString());
+ EXPECT_EQ(exp_str, name_change_->transactionOutcomeString());
}
/// @brief Tests event and state dictionary construction and verification.
TEST_F(NameChangeTransactionTest, dictionaryCheck) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Verify that the event and state dictionary validation fails prior
// dictionary construction.
- ASSERT_THROW(name_change->verifyEvents(), StateModelError);
- ASSERT_THROW(name_change->verifyStates(), StateModelError);
+ ASSERT_THROW(name_change_->verifyEvents(), StateModelError);
+ ASSERT_THROW(name_change_->verifyStates(), StateModelError);
// Construct both dictionaries.
- ASSERT_NO_THROW(name_change->defineEvents());
- ASSERT_NO_THROW(name_change->defineStates());
+ ASSERT_NO_THROW(name_change_->defineEvents());
+ ASSERT_NO_THROW(name_change_->defineStates());
// Verify both event and state dictionaries now pass validation.
- ASSERT_NO_THROW(name_change->verifyEvents());
- ASSERT_NO_THROW(name_change->verifyStates());
+ ASSERT_NO_THROW(name_change_->verifyEvents());
+ ASSERT_NO_THROW(name_change_->verifyStates());
}
/// @brief Tests server selection methods.
@@ -646,11 +652,10 @@ TEST_F(NameChangeTransactionTest, dictionaryCheck) {
/// when a DNS exchange fails due to an IO error. This test verifies the
/// ability to iteratively select a server from the list as the current server.
TEST_F(NameChangeTransactionTest, serverSelectionTest) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Verify that the forward domain and its list of servers can be retrieved.
- DdnsDomainPtr& domain = name_change->getForwardDomain();
+ DdnsDomainPtr& domain = name_change_->getForwardDomain();
ASSERT_TRUE(domain);
DnsServerInfoStoragePtr servers = domain->getServers();
ASSERT_TRUE(servers);
@@ -662,39 +667,39 @@ TEST_F(NameChangeTransactionTest, serverSelectionTest) {
// Verify that we can initialize server selection. This "resets" the
// selection process to start over using the list of servers in the
// given domain.
- ASSERT_NO_THROW(name_change->initServerSelection(domain));
+ ASSERT_NO_THROW(name_change_->initServerSelection(domain));
// The server selection process determines the current server,
// instantiates a new DNSClient, and a DNS response message buffer.
// We need to save the values before each selection, so we can verify
// they are correct after each selection.
- DnsServerInfoPtr prev_server = name_change->getCurrentServer();
- DNSClientPtr prev_client = name_change->getDNSClient();
+ DnsServerInfoPtr prev_server = name_change_->getCurrentServer();
+ DNSClientPtr prev_client = name_change_->getDNSClient();
// Verify response pointer is empty.
- EXPECT_FALSE(name_change->getDnsUpdateResponse());
+ EXPECT_FALSE(name_change_->getDnsUpdateResponse());
// Create dummy response so we can verify it is cleared at each
// new server select.
D2UpdateMessagePtr dummyResp;
dummyResp.reset(new D2UpdateMessage(D2UpdateMessage::INBOUND));
- ASSERT_NO_THROW(name_change->setDnsUpdateResponse(dummyResp));
- ASSERT_TRUE(name_change->getDnsUpdateResponse());
+ ASSERT_NO_THROW(name_change_->setDnsUpdateResponse(dummyResp));
+ ASSERT_TRUE(name_change_->getDnsUpdateResponse());
// Iteratively select through the list of servers.
int passes = 0;
- while (name_change->selectNextServer()) {
+ while (name_change_->selectNextServer()) {
// Get the new values after the selection has been made.
- DnsServerInfoPtr server = name_change->getCurrentServer();
- DNSClientPtr client = name_change->getDNSClient();
- D2UpdateMessagePtr response = name_change->getDnsUpdateResponse();
+ DnsServerInfoPtr server = name_change_->getCurrentServer();
+ DNSClientPtr client = name_change_->getDNSClient();
+ D2UpdateMessagePtr response = name_change_->getDnsUpdateResponse();
// Verify that the new values are not empty.
EXPECT_TRUE(server);
EXPECT_TRUE(client);
// Verify response pointer is now empty.
- EXPECT_FALSE(name_change->getDnsUpdateResponse());
+ EXPECT_FALSE(name_change_->getDnsUpdateResponse());
// Verify that the new values are indeed new.
EXPECT_NE(server, prev_server);
@@ -706,18 +711,18 @@ TEST_F(NameChangeTransactionTest, serverSelectionTest) {
// Create new dummy response.
dummyResp.reset(new D2UpdateMessage(D2UpdateMessage::INBOUND));
- ASSERT_NO_THROW(name_change->setDnsUpdateResponse(dummyResp));
- ASSERT_TRUE(name_change->getDnsUpdateResponse());
+ ASSERT_NO_THROW(name_change_->setDnsUpdateResponse(dummyResp));
+ ASSERT_TRUE(name_change_->getDnsUpdateResponse());
++passes;
}
// Verify that the number of passes made equal the number of servers.
- EXPECT_EQ (passes, num_servers);
+ EXPECT_EQ(passes, num_servers);
// Repeat the same test using the reverse domain.
// Verify that the reverse domain and its list of servers can be retrieved.
- domain = name_change->getReverseDomain();
+ domain = name_change_->getReverseDomain();
ASSERT_TRUE(domain);
servers = domain->getServers();
ASSERT_TRUE(servers);
@@ -729,29 +734,29 @@ TEST_F(NameChangeTransactionTest, serverSelectionTest) {
// Verify that we can initialize server selection. This "resets" the
// selection process to start over using the list of servers in the
// given domain.
- ASSERT_NO_THROW(name_change->initServerSelection(domain));
+ ASSERT_NO_THROW(name_change_->initServerSelection(domain));
// The server selection process determines the current server,
// instantiates a new DNSClient, and resets the DNS response message buffer.
// We need to save the values before each selection, so we can verify
// they are correct after each selection.
- prev_server = name_change->getCurrentServer();
- prev_client = name_change->getDNSClient();
+ prev_server = name_change_->getCurrentServer();
+ prev_client = name_change_->getDNSClient();
// Iteratively select through the list of servers.
passes = 0;
- while (name_change->selectNextServer()) {
+ while (name_change_->selectNextServer()) {
// Get the new values after the selection has been made.
- DnsServerInfoPtr server = name_change->getCurrentServer();
- DNSClientPtr client = name_change->getDNSClient();
- D2UpdateMessagePtr response = name_change->getDnsUpdateResponse();
+ DnsServerInfoPtr server = name_change_->getCurrentServer();
+ DNSClientPtr client = name_change_->getDNSClient();
+ D2UpdateMessagePtr response = name_change_->getDnsUpdateResponse();
// Verify that the new values are not empty.
EXPECT_TRUE(server);
EXPECT_TRUE(client);
// Verify response pointer is now empty.
- EXPECT_FALSE(name_change->getDnsUpdateResponse());
+ EXPECT_FALSE(name_change_->getDnsUpdateResponse());
// Verify that the new values are indeed new.
EXPECT_NE(server, prev_server);
@@ -763,123 +768,119 @@ TEST_F(NameChangeTransactionTest, serverSelectionTest) {
// Create new dummy response.
dummyResp.reset(new D2UpdateMessage(D2UpdateMessage::INBOUND));
- ASSERT_NO_THROW(name_change->setDnsUpdateResponse(dummyResp));
- ASSERT_TRUE(name_change->getDnsUpdateResponse());
+ ASSERT_NO_THROW(name_change_->setDnsUpdateResponse(dummyResp));
+ ASSERT_TRUE(name_change_->getDnsUpdateResponse());
++passes;
}
// Verify that the number of passes made equal the number of servers.
- EXPECT_EQ (passes, num_servers);
+ EXPECT_EQ(passes, num_servers);
}
/// @brief Tests that the transaction will be "failed" upon model errors.
TEST_F(NameChangeTransactionTest, modelFailure) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Now call runModel() with an undefined event which should not throw,
// but should result in a failed model and failed transaction.
- EXPECT_NO_THROW(name_change->runModel(9999));
+ EXPECT_NO_THROW(name_change_->runModel(9999));
// Verify that the model reports are done but failed.
- EXPECT_TRUE(name_change->isModelDone());
- EXPECT_TRUE(name_change->didModelFail());
+ EXPECT_TRUE(name_change_->isModelDone());
+ EXPECT_TRUE(name_change_->didModelFail());
// Verify that the transaction has failed.
- EXPECT_EQ(dhcp_ddns::ST_FAILED, name_change->getNcrStatus());
+ EXPECT_EQ(dhcp_ddns::ST_FAILED, name_change_->getNcrStatus());
}
/// @brief Tests the ability to use startTransaction to initiate the state
/// model execution, and DNSClient callback, operator(), to resume the
/// model with a update successful outcome.
TEST_F(NameChangeTransactionTest, successfulUpdateTest) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ASSERT_TRUE(name_change_->selectFwdServer());
- EXPECT_TRUE(name_change->isModelNew());
- EXPECT_FALSE(name_change->getForwardChangeCompleted());
+ EXPECT_TRUE(name_change_->isModelNew());
+ EXPECT_FALSE(name_change_->getForwardChangeCompleted());
// Launch the transaction by calling startTransaction. The state model
// should run up until the "IO" operation is initiated in DOING_UPDATE_ST.
- ASSERT_NO_THROW(name_change->startTransaction());
+ ASSERT_NO_THROW(name_change_->startTransaction());
// Verify that the model is running but waiting, and that forward change
// completion is still false.
- EXPECT_TRUE(name_change->isModelRunning());
- EXPECT_TRUE(name_change->isModelWaiting());
- EXPECT_FALSE(name_change->getForwardChangeCompleted());
+ EXPECT_TRUE(name_change_->isModelRunning());
+ EXPECT_TRUE(name_change_->isModelWaiting());
+ EXPECT_FALSE(name_change_->getForwardChangeCompleted());
// Simulate completion of DNSClient exchange by invoking the callback, as
// DNSClient would. This should cause the state model to progress through
// completion.
- EXPECT_NO_THROW((*name_change)(DNSClient::SUCCESS));
+ EXPECT_NO_THROW((*name_change_)(DNSClient::SUCCESS));
// The model should have worked through to completion.
// Verify that the model is done and not failed.
- EXPECT_TRUE(name_change->isModelDone());
- EXPECT_FALSE(name_change->didModelFail());
+ EXPECT_TRUE(name_change_->isModelDone());
+ EXPECT_FALSE(name_change_->didModelFail());
// Verify that NCR status is completed, and that the forward change
// was completed.
- EXPECT_EQ(dhcp_ddns::ST_COMPLETED, name_change->getNcrStatus());
- EXPECT_TRUE(name_change->getForwardChangeCompleted());
+ EXPECT_EQ(dhcp_ddns::ST_COMPLETED, name_change_->getNcrStatus());
+ EXPECT_TRUE(name_change_->getForwardChangeCompleted());
}
/// @brief Tests the ability to use startTransaction to initiate the state
/// model execution, and DNSClient callback, operator(), to resume the
/// model with a update failure outcome.
TEST_F(NameChangeTransactionTest, failedUpdateTest) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Launch the transaction by calling startTransaction. The state model
// should run up until the "IO" operation is initiated in DOING_UPDATE_ST.
- ASSERT_NO_THROW(name_change->startTransaction());
+ ASSERT_NO_THROW(name_change_->startTransaction());
// Verify that the model is running but waiting, and that the forward
// change has not been completed.
- EXPECT_TRUE(name_change->isModelRunning());
- EXPECT_TRUE(name_change->isModelWaiting());
- EXPECT_FALSE(name_change->getForwardChangeCompleted());
+ EXPECT_TRUE(name_change_->isModelRunning());
+ EXPECT_TRUE(name_change_->isModelWaiting());
+ EXPECT_FALSE(name_change_->getForwardChangeCompleted());
// Simulate completion of DNSClient exchange by invoking the callback, as
// DNSClient would. This should cause the state model to progress through
// to completion.
- EXPECT_NO_THROW((*name_change)(DNSClient::TIMEOUT));
+ EXPECT_NO_THROW((*name_change_)(DNSClient::TIMEOUT));
// The model should have worked through to completion.
// Verify that the model is done and not failed.
- EXPECT_TRUE(name_change->isModelDone());
- EXPECT_FALSE(name_change->didModelFail());
+ EXPECT_TRUE(name_change_->isModelDone());
+ EXPECT_FALSE(name_change_->didModelFail());
// Verify that the NCR status is failed and that the forward change
// was not completed.
- EXPECT_EQ(dhcp_ddns::ST_FAILED, name_change->getNcrStatus());
- EXPECT_FALSE(name_change->getForwardChangeCompleted());
+ EXPECT_EQ(dhcp_ddns::ST_FAILED, name_change_->getNcrStatus());
+ EXPECT_FALSE(name_change_->getForwardChangeCompleted());
}
/// @brief Tests update attempt accessors.
TEST_F(NameChangeTransactionTest, updateAttempts) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Post transaction construction, update attempts should be 0.
- EXPECT_EQ(0, name_change->getUpdateAttempts());
+ EXPECT_EQ(0, name_change_->getUpdateAttempts());
// Set it to a known value.
- name_change->setUpdateAttempts(5);
+ name_change_->setUpdateAttempts(5);
// Verify that the value is as expected.
- EXPECT_EQ(5, name_change->getUpdateAttempts());
+ EXPECT_EQ(5, name_change_->getUpdateAttempts());
// Clear it.
- name_change->clearUpdateAttempts();
+ name_change_->clearUpdateAttempts();
// Verify that it was cleared as expected.
- EXPECT_EQ(0, name_change->getUpdateAttempts());
+ EXPECT_EQ(0, name_change_->getUpdateAttempts());
}
/// @brief Tests retryTransition method
@@ -890,52 +891,51 @@ TEST_F(NameChangeTransactionTest, updateAttempts) {
/// transition to the state given with a next event of SERVER_IO_ERROR_EVT.
TEST_F(NameChangeTransactionTest, retryTransition) {
// Create the transaction.
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
// Define dictionaries.
- ASSERT_NO_THROW(name_change->initDictionaries());
+ ASSERT_NO_THROW(name_change_->initDictionaries());
// Transition to a known spot.
- ASSERT_NO_THROW(name_change->transition(
+ ASSERT_NO_THROW(name_change_->transition(
NameChangeStub::DOING_UPDATE_ST,
NameChangeStub::SEND_UPDATE_EVT));
// Verify we are at the known spot.
ASSERT_EQ(NameChangeStub::DOING_UPDATE_ST,
- name_change->getCurrState());
+ name_change_->getCurrState());
ASSERT_EQ(NameChangeStub::SEND_UPDATE_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
// Verify that we have not exceeded maximum number of attempts.
- ASSERT_LT(name_change->getUpdateAttempts(),
+ ASSERT_LT(name_change_->getUpdateAttempts(),
NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER);
// Call retryTransition.
- ASSERT_NO_THROW(name_change->retryTransition(
+ ASSERT_NO_THROW(name_change_->retryTransition(
NameChangeTransaction::PROCESS_TRANS_FAILED_ST));
// Since the number of update attempts is less than the maximum allowed
// we should remain in our current state but with next event of
// SERVER_SELECTED_EVT posted.
ASSERT_EQ(NameChangeStub::DOING_UPDATE_ST,
- name_change->getCurrState());
+ name_change_->getCurrState());
ASSERT_EQ(NameChangeTransaction::SERVER_SELECTED_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
// Now set the number of attempts to the maximum.
- name_change->setUpdateAttempts(NameChangeTransaction::
- MAX_UPDATE_TRIES_PER_SERVER);
+ name_change_->setUpdateAttempts(NameChangeTransaction::
+ MAX_UPDATE_TRIES_PER_SERVER);
// Call retryTransition.
- ASSERT_NO_THROW(name_change->retryTransition(
+ ASSERT_NO_THROW(name_change_->retryTransition(
NameChangeTransaction::PROCESS_TRANS_FAILED_ST));
// Since we have exceeded maximum attempts, we should transition to
// PROCESS_UPDATE_FAILED_ST with a next event of SERVER_IO_ERROR_EVT.
ASSERT_EQ(NameChangeTransaction::PROCESS_TRANS_FAILED_ST,
- name_change->getCurrState());
+ name_change_->getCurrState());
ASSERT_EQ(NameChangeTransaction::SERVER_IO_ERROR_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
}
/// @brief Tests sendUpdate method when underlying doUpdate throws.
@@ -944,33 +944,31 @@ TEST_F(NameChangeTransactionTest, retryTransition) {
/// sendUpdate handling of such a throw by passing doUpdate a request
/// that will not render.
TEST_F(NameChangeTransactionTest, sendUpdateDoUpdateFailure) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Set the transaction's request to an empty DNS update.
D2UpdateMessagePtr req;
ASSERT_NO_THROW(req.reset(new D2UpdateMessage(D2UpdateMessage::OUTBOUND)));
- ASSERT_NO_THROW(name_change->setDnsUpdateRequest(req));
+ ASSERT_NO_THROW(name_change_->setDnsUpdateRequest(req));
// Verify that sendUpdate does not throw, but it should fail because
// the request won't render.
- ASSERT_NO_THROW(name_change->sendUpdate());
+ ASSERT_NO_THROW(name_change_->sendUpdate());
// Verify that we transition to failed state and event.
ASSERT_EQ(NameChangeTransaction::PROCESS_TRANS_FAILED_ST,
- name_change->getCurrState());
+ name_change_->getCurrState());
ASSERT_EQ(NameChangeTransaction::UPDATE_FAILED_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
}
/// @brief Tests sendUpdate method when underlying doUpdate times out.
TEST_F(NameChangeTransactionTest, sendUpdateTimeout) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Build a valid request, call sendUpdate and process the response.
// Note we have to wait for DNSClient timeout plus a bit more to allow
@@ -983,57 +981,55 @@ TEST_F(NameChangeTransactionTest, sendUpdateTimeout) {
D2ParamsPtr d2_params = cfg_mgr_->getD2Params();
size_t timeout = d2_params->getDnsServerTimeout() + 100;
- ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change, timeout));
+ ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change_, timeout));
// Verify that next event is IO_COMPLETED_EVT and DNS status is TIMEOUT.
ASSERT_EQ(NameChangeTransaction::IO_COMPLETED_EVT,
- name_change->getNextEvent());
- ASSERT_EQ(DNSClient::TIMEOUT, name_change->getDnsUpdateStatus());
+ name_change_->getNextEvent());
+ ASSERT_EQ(DNSClient::TIMEOUT, name_change_->getDnsUpdateStatus());
}
/// @brief Tests sendUpdate method when it receives a corrupt response from
/// the server.
TEST_F(NameChangeTransactionTest, sendUpdateCorruptResponse) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Create a server and start it listening.
- FauxServer server(io_service_, *(name_change->getCurrentServer()));
- server.receive(FauxServer::CORRUPT_RESP);
+ server_.reset(new FauxServer(io_service_, *(name_change_->getCurrentServer())));
+ server_->receive(FauxServer::CORRUPT_RESP);
// Build a valid request, call sendUpdate and process the response.
- ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change));
+ ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change_));
// Verify that next event is IO_COMPLETED_EVT and DNS status is INVALID.
ASSERT_EQ(NameChangeTransaction::IO_COMPLETED_EVT,
- name_change->getNextEvent());
- ASSERT_EQ(DNSClient::INVALID_RESPONSE, name_change->getDnsUpdateStatus());
+ name_change_->getNextEvent());
+ ASSERT_EQ(DNSClient::INVALID_RESPONSE, name_change_->getDnsUpdateStatus());
}
/// @brief Tests sendUpdate method when the exchange succeeds.
TEST_F(NameChangeTransactionTest, sendUpdate) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Create a server and start it listening.
- FauxServer server(io_service_, *(name_change->getCurrentServer()));
- server.receive (FauxServer::USE_RCODE, dns::Rcode::NOERROR());
+ server_.reset(new FauxServer(io_service_, *(name_change_->getCurrentServer())));
+ server_->receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Build a valid request, call sendUpdate and process the response.
- ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change));
+ ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change_));
// Verify that next event is IO_COMPLETED_EVT and DNS status is SUCCESS.
ASSERT_EQ(NameChangeTransaction::IO_COMPLETED_EVT,
- name_change->getNextEvent());
- ASSERT_EQ(DNSClient::SUCCESS, name_change->getDnsUpdateStatus());
+ name_change_->getNextEvent());
+ ASSERT_EQ(DNSClient::SUCCESS, name_change_->getDnsUpdateStatus());
// Verify that we have a response and it's Rcode is NOERROR,
// and the zone is as expected.
- D2UpdateMessagePtr response = name_change->getDnsUpdateResponse();
+ D2UpdateMessagePtr response = name_change_->getDnsUpdateResponse();
ASSERT_TRUE(response);
ASSERT_EQ(dns::Rcode::NOERROR().getCode(), response->getRcode().getCode());
D2ZonePtr zone = response->getZone();
@@ -1043,29 +1039,28 @@ TEST_F(NameChangeTransactionTest, sendUpdate) {
/// @brief Tests that an unsigned response to a signed request is an error
TEST_F(NameChangeTransactionTest, tsigUnsignedResponse) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction("key_one"));
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction("key_one"));
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Create a server and start it listening.
- FauxServer server(io_service_, *(name_change->getCurrentServer()));
- server.receive (FauxServer::USE_RCODE, dns::Rcode::NOERROR());
+ server_.reset(new FauxServer(io_service_, *(name_change_->getCurrentServer())));
+ server_->receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Do the update.
- ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change));
+ ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change_));
// Verify that next event is IO_COMPLETED_EVT and DNS status is
// INVALID_RESPONSE.
ASSERT_EQ(NameChangeTransaction::IO_COMPLETED_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
- ASSERT_EQ(DNSClient::INVALID_RESPONSE, name_change->getDnsUpdateStatus());
+ ASSERT_EQ(DNSClient::INVALID_RESPONSE, name_change_->getDnsUpdateStatus());
// When TSIG errors occur, only the message header (including Rcode) is
// unpacked. In this case, it should be NOERROR but have no other
// information.
- D2UpdateMessagePtr response = name_change->getDnsUpdateResponse();
+ D2UpdateMessagePtr response = name_change_->getDnsUpdateResponse();
ASSERT_TRUE(response);
ASSERT_EQ(dns::Rcode::NOERROR().getCode(), response->getRcode().getCode());
EXPECT_FALSE(response->getZone());
@@ -1073,30 +1068,29 @@ TEST_F(NameChangeTransactionTest, tsigUnsignedResponse) {
/// @brief Tests that a response signed with the wrong key is an error
TEST_F(NameChangeTransactionTest, tsigInvalidResponse) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction("key_one"));
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction("key_one"));
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Create a server, tell it to sign responses with a "random" key,
// then start it listening.
- FauxServer server(io_service_, *(name_change->getCurrentServer()));
- server.receive (FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
+ server_.reset(new FauxServer(io_service_, *(name_change_->getCurrentServer())));
+ server_->receive(FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
// Do the update.
- ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change));
+ ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change_));
// Verify that next event is IO_COMPLETED_EVT and DNS status is
// INVALID_RESPONSE.
ASSERT_EQ(NameChangeTransaction::IO_COMPLETED_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
- ASSERT_EQ(DNSClient::INVALID_RESPONSE, name_change->getDnsUpdateStatus());
+ ASSERT_EQ(DNSClient::INVALID_RESPONSE, name_change_->getDnsUpdateStatus());
// When TSIG errors occur, only the message header (including Rcode) is
// unpacked. In this case, it should be NOERROR but have no other
// information.
- D2UpdateMessagePtr response = name_change->getDnsUpdateResponse();
+ D2UpdateMessagePtr response = name_change_->getDnsUpdateResponse();
ASSERT_TRUE(response);
ASSERT_EQ(dns::Rcode::NOERROR().getCode(), response->getRcode().getCode());
EXPECT_FALSE(response->getZone());
@@ -1106,26 +1100,25 @@ TEST_F(NameChangeTransactionTest, tsigInvalidResponse) {
/// Currently our policy is to accept a signed response to an unsigned request
/// even though the spec says a server MUST not do that.
TEST_F(NameChangeTransactionTest, tsigUnexpectedSignedResponse) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Create a server, tell it to sign responses with a "random" key,
// then start it listening.
- FauxServer server(io_service_, *(name_change->getCurrentServer()));
- server.receive (FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
+ server_.reset(new FauxServer(io_service_, *(name_change_->getCurrentServer())));
+ server_->receive(FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
// Perform an update without TSIG.
- ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change));
+ ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change_));
// Verify that next event is IO_COMPLETED_EVT and DNS status is SUCCESS.
ASSERT_EQ(NameChangeTransaction::IO_COMPLETED_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
- ASSERT_EQ(DNSClient::SUCCESS, name_change->getDnsUpdateStatus());
+ ASSERT_EQ(DNSClient::SUCCESS, name_change_->getDnsUpdateStatus());
- D2UpdateMessagePtr response = name_change->getDnsUpdateResponse();
+ D2UpdateMessagePtr response = name_change_->getDnsUpdateResponse();
ASSERT_TRUE(response);
ASSERT_EQ(dns::Rcode::NOERROR().getCode(), response->getRcode().getCode());
D2ZonePtr zone = response->getZone();
@@ -1145,34 +1138,33 @@ TEST_F(NameChangeTransactionTest, tsigAllValid) {
algorithms.push_back(TSIGKeyInfo::HMAC_SHA512_STR);
for (int i = 0; i < algorithms.size(); ++i) {
- SCOPED_TRACE (algorithms[i]);
+ SCOPED_TRACE(algorithms[i]);
TSIGKeyInfoPtr key;
ASSERT_NO_THROW(key.reset(new TSIGKeyInfo("test_key",
algorithms[i],
"GWG/Xfbju4O2iXGqkSu4PQ==")));
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction(key));
- ASSERT_NO_THROW(name_change->initDictionaries());
- ASSERT_TRUE(name_change->selectFwdServer());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction(key));
+ ASSERT_NO_THROW(name_change_->initDictionaries());
+ ASSERT_TRUE(name_change_->selectFwdServer());
// Create a server, set its TSIG key, and then start it listening.
- FauxServer server(io_service_, *(name_change->getCurrentServer()));
+ server_.reset(new FauxServer(io_service_, *(name_change_->getCurrentServer())));
// Since we create a new server instance each time we need to tell
// it not reschedule receives automatically.
- server.perpetual_receive_ = false;
- server.setTSIGKey(key->getTSIGKey());
- server.receive (FauxServer::USE_RCODE, dns::Rcode::NOERROR());
+ server_->perpetual_receive_ = false;
+ server_->setTSIGKey(key->getTSIGKey());
+ server_->receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Do the update.
- ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change));
+ ASSERT_NO_FATAL_FAILURE(doOneExchange(name_change_));
// Verify that next event is IO_COMPLETED_EVT and DNS status is SUCCESS.
ASSERT_EQ(NameChangeTransaction::IO_COMPLETED_EVT,
- name_change->getNextEvent());
+ name_change_->getNextEvent());
- ASSERT_EQ(DNSClient::SUCCESS, name_change->getDnsUpdateStatus());
+ ASSERT_EQ(DNSClient::SUCCESS, name_change_->getDnsUpdateStatus());
- D2UpdateMessagePtr response = name_change->getDnsUpdateResponse();
+ D2UpdateMessagePtr response = name_change_->getDnsUpdateResponse();
ASSERT_TRUE(response);
ASSERT_EQ(dns::Rcode::NOERROR().getCode(),
response->getRcode().getCode());
@@ -1182,33 +1174,31 @@ TEST_F(NameChangeTransactionTest, tsigAllValid) {
}
}
-
/// @brief Tests the prepNewRequest method
TEST_F(NameChangeTransactionTest, prepNewRequest) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
D2UpdateMessagePtr request;
// prepNewRequest should fail on empty domain.
- ASSERT_THROW(request = name_change->prepNewRequest(DdnsDomainPtr()),
+ ASSERT_THROW(request = name_change_->prepNewRequest(DdnsDomainPtr()),
NameChangeTransactionError);
// Verify that prepNewRequest fails on invalid zone name.
// @todo This test becomes obsolete if/when DdnsDomain enforces valid
// names as is done in dns::Name.
DdnsDomainPtr bsDomain = makeDomain(".badname","");
- ASSERT_THROW(request = name_change->prepNewRequest(bsDomain),
+ ASSERT_THROW(request = name_change_->prepNewRequest(bsDomain),
NameChangeTransactionError);
// Verify that prepNewRequest properly constructs a message given
// valid input.
- ASSERT_NO_THROW(request = name_change->prepNewRequest(forward_domain_));
+ ASSERT_NO_THROW(request = name_change_->prepNewRequest(forward_domain_));
checkZone(request, forward_domain_->getName());
// The query id is random so 0 is not impossible
for (unsigned i = 0; i < 10; ++i) {
if (request->getId() == 0) {
- request = name_change->prepNewRequest(forward_domain_);
+ request = name_change_->prepNewRequest(forward_domain_);
}
}
@@ -1217,15 +1207,14 @@ TEST_F(NameChangeTransactionTest, prepNewRequest) {
/// @brief Tests the addLeaseAddressRData method
TEST_F(NameChangeTransactionTest, addLeaseAddressRData) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- dhcp_ddns::NameChangeRequestPtr ncr = name_change->getNcr();
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ dhcp_ddns::NameChangeRequestPtr ncr = name_change_->getNcr();
// Verify we can add a lease RData to an valid RRset.
dns::RRsetPtr rrset(new dns::RRset(dns::Name("bs"), dns::RRClass::IN(),
- name_change->getAddressRRType(),
+ name_change_->getAddressRRType(),
dns::RRTTL(0)));
- ASSERT_NO_THROW(name_change->addLeaseAddressRdata(rrset));
+ ASSERT_NO_THROW(name_change_->addLeaseAddressRdata(rrset));
// Verify the Rdata was added and the value is correct.
ASSERT_EQ(1, rrset->getRdataCount());
@@ -1237,14 +1226,13 @@ TEST_F(NameChangeTransactionTest, addLeaseAddressRData) {
/// @brief Tests the addDhcidRData method
TEST_F(NameChangeTransactionTest, addDhcidRdata) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- dhcp_ddns::NameChangeRequestPtr ncr = name_change->getNcr();
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ dhcp_ddns::NameChangeRequestPtr ncr = name_change_->getNcr();
// Verify we can add a lease RData to an valid RRset.
dns::RRsetPtr rrset(new dns::RRset(dns::Name("bs"), dns::RRClass::IN(),
dns::RRType::DHCID(), dns::RRTTL(0)));
- ASSERT_NO_THROW(name_change->addDhcidRdata(rrset));
+ ASSERT_NO_THROW(name_change_->addDhcidRdata(rrset));
// Verify the Rdata was added and the value is correct.
ASSERT_EQ(1, rrset->getRdataCount());
@@ -1259,14 +1247,13 @@ TEST_F(NameChangeTransactionTest, addDhcidRdata) {
/// @brief Tests the addPtrData method
TEST_F(NameChangeTransactionTest, addPtrRdata) {
- NameChangeStubPtr name_change;
- ASSERT_NO_THROW(name_change = makeCannedTransaction());
- dhcp_ddns::NameChangeRequestPtr ncr = name_change->getNcr();
+ ASSERT_NO_THROW(name_change_ = makeCannedTransaction());
+ dhcp_ddns::NameChangeRequestPtr ncr = name_change_->getNcr();
// Verify we can add a PTR RData to an valid RRset.
- dns::RRsetPtr rrset (new dns::RRset(dns::Name("bs"), dns::RRClass::IN(),
+ dns::RRsetPtr rrset(new dns::RRset(dns::Name("bs"), dns::RRClass::IN(),
dns::RRType::PTR(), dns::RRTTL(0)));
- ASSERT_NO_THROW(name_change->addPtrRdata(rrset));
+ ASSERT_NO_THROW(name_change_->addPtrRdata(rrset));
// Verify the Rdata was added and the value is correct.
ASSERT_EQ(1, rrset->getRdataCount());
diff --git a/src/lib/d2srv/testutils/nc_test_utils.cc b/src/lib/d2srv/testutils/nc_test_utils.cc
index 56c3988e3b..1aceb6acbc 100644
--- a/src/lib/d2srv/testutils/nc_test_utils.cc
+++ b/src/lib/d2srv/testutils/nc_test_utils.cc
@@ -211,11 +211,18 @@ FauxServer::requestHandler(const boost::system::error_code& error,
//********************** TimedIO class ***********************
TimedIO::TimedIO()
- : io_service_(new isc::asiolink::IOService()), timer_(io_service_),
+ : io_service_(new isc::asiolink::IOService()),
+ timer_(new asiolink::IntervalTimer(io_service_)),
run_time_(0) {
}
TimedIO::~TimedIO() {
+ timer_->cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
int
@@ -223,9 +230,9 @@ TimedIO::runTimedIO(int run_time) {
run_time_ = run_time;
int cnt = io_service_->poll();
if (cnt == 0) {
- timer_.setup(std::bind(&TimedIO::timesUp, this), run_time_);
+ timer_->setup(std::bind(&TimedIO::timesUp, this), run_time_);
cnt = io_service_->runOne();
- timer_.cancel();
+ timer_->cancel();
}
return (cnt);
diff --git a/src/lib/d2srv/testutils/nc_test_utils.h b/src/lib/d2srv/testutils/nc_test_utils.h
index cd6152cd82..cb30995747 100644
--- a/src/lib/d2srv/testutils/nc_test_utils.h
+++ b/src/lib/d2srv/testutils/nc_test_utils.h
@@ -98,8 +98,8 @@ public:
/// @param response_mode Selects how the server responds to a request
/// @param response_rcode The Rcode value set in the response. Not used
/// for all modes.
- void receive (const ResponseMode& response_mode,
- const dns::Rcode& response_rcode=dns::Rcode::NOERROR());
+ void receive(const ResponseMode& response_mode,
+ const dns::Rcode& response_rcode=dns::Rcode::NOERROR());
/// @brief Socket IO Completion callback
///
@@ -143,7 +143,7 @@ public:
class TimedIO {
public:
asiolink::IOServicePtr io_service_;
- asiolink::IntervalTimer timer_;
+ asiolink::IntervalTimerPtr timer_;
int run_time_;
/// @brief Constructor
diff --git a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
index bb48609814..ea074ba672 100644
--- a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
+++ b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
@@ -179,7 +179,13 @@ public:
TEST_TIMEOUT);
}
- virtual ~NameChangeUDPListenerTest(){
+ virtual ~NameChangeUDPListenerTest() {
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
@@ -987,6 +993,12 @@ public:
}
~NameChangeUDPTest() {
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
// Disable multi-threading
MultiThreadingMgr::instance().setMode(false);
}
diff --git a/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc b/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
index 067a697809..bceb7960e4 100644
--- a/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
+++ b/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
@@ -310,6 +310,11 @@ public:
/// timers.
virtual ~CfgExpirationTimersTest() {
cleanupTimerMgr();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Stop @c TimerMgr worker thread and remove the timers.
diff --git a/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc b/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
index e76474a54d..c991b5577a 100644
--- a/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
@@ -147,6 +147,11 @@ void
TimerMgrTest::TearDown() {
// Remove all timers.
timer_mgr_->unregisterTimers();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
void
diff --git a/src/lib/http/tests/client_mt_unittests.cc b/src/lib/http/tests/client_mt_unittests.cc
index bb39f68e14..ea15dc0fac 100644
--- a/src/lib/http/tests/client_mt_unittests.cc
+++ b/src/lib/http/tests/client_mt_unittests.cc
@@ -217,6 +217,13 @@ public:
listener->stop();
}
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
+
MultiThreadingMgr::instance().setMode(false);
}
diff --git a/src/lib/http/tests/connection_pool_unittests.cc b/src/lib/http/tests/connection_pool_unittests.cc
index d6267a0e14..2bb4047481 100644
--- a/src/lib/http/tests/connection_pool_unittests.cc
+++ b/src/lib/http/tests/connection_pool_unittests.cc
@@ -114,6 +114,11 @@ public:
/// @brief Destructor.
~HttpConnectionPoolTest() {
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
MultiThreadingMgr::instance().setMode(false);
}
diff --git a/src/lib/http/tests/server_client_unittests.cc b/src/lib/http/tests/server_client_unittests.cc
index 6572e8381a..059845b06d 100644
--- a/src/lib/http/tests/server_client_unittests.cc
+++ b/src/lib/http/tests/server_client_unittests.cc
@@ -412,6 +412,12 @@ public:
for (auto const& client : clients_) {
client->close();
}
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Connect to the endpoint.
diff --git a/src/lib/http/tests/tls_client_unittests.cc b/src/lib/http/tests/tls_client_unittests.cc
index 4309a87456..5102737544 100644
--- a/src/lib/http/tests/tls_client_unittests.cc
+++ b/src/lib/http/tests/tls_client_unittests.cc
@@ -233,6 +233,16 @@ public:
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
}
+ /// @brief Destructor.
+ virtual ~HttpListenerTest() {
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
+ }
+
/// @brief Callback function invoke upon test timeout.
///
/// It stops the IO service and reports test timeout.
diff --git a/src/lib/http/tests/tls_server_unittests.cc b/src/lib/http/tests/tls_server_unittests.cc
index db788ce56f..29e50c1de5 100644
--- a/src/lib/http/tests/tls_server_unittests.cc
+++ b/src/lib/http/tests/tls_server_unittests.cc
@@ -659,6 +659,12 @@ public:
for (auto const& client : clients_) {
client->close();
}
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Connect to the endpoint.
diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc
index 7946a5c66d..b1661db286 100644
--- a/src/lib/process/d_controller.cc
+++ b/src/lib/process/d_controller.cc
@@ -50,8 +50,7 @@ DControllerBase::setController(const DControllerBasePtr& controller) {
if (controller_) {
// This shouldn't happen, but let's make sure it can't be done.
// It represents a programmatic error.
- isc_throw (DControllerBaseError,
- "Multiple controller instances attempted.");
+ isc_throw (DControllerBaseError, "Multiple controller instances attempted.");
}
controller_ = controller;
diff --git a/src/lib/tcp/mt_tcp_listener_mgr.cc b/src/lib/tcp/mt_tcp_listener_mgr.cc
index aca4f1d650..6bdc83d202 100644
--- a/src/lib/tcp/mt_tcp_listener_mgr.cc
+++ b/src/lib/tcp/mt_tcp_listener_mgr.cc
@@ -78,9 +78,14 @@ MtTcpListenerMgr::start() {
.arg(port_)
.arg(tls_context_ ? "true" : "false");
} catch (const std::exception& ex) {
- thread_io_service_.reset();
tcp_listener_.reset();
thread_pool_.reset();
+ thread_io_service_->restart();
+ try {
+ thread_io_service_->poll();
+ } catch (...) {
+ }
+ thread_io_service_.reset();
isc_throw(Unexpected, "MtTcpListenerMgr::start failed:" << ex.what());
}
}
@@ -123,6 +128,12 @@ MtTcpListenerMgr::stop() {
// Get rid of the listener.
tcp_listener_.reset();
+ thread_io_service_->restart();
+ try {
+ thread_io_service_->poll();
+ } catch (...) {
+ }
+
// Ditch the IOService.
thread_io_service_.reset();
diff --git a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
index 782d7efb3e..cd4dc12345 100644
--- a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
+++ b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
@@ -74,6 +74,13 @@ public:
client->close();
}
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
+
// Disable multi-threading.
MultiThreadingMgr::instance().setMode(false);
}
@@ -804,6 +811,8 @@ TEST_F(MtTcpListenerMgrTest, basics) {
ASSERT_THROW_MSG(mt_listener_mgr_->start(), InvalidOperation,
"MtTcpListenerMgr already started!");
+ return;
+
// Stop it and verify we're no longer listening.
ASSERT_NO_THROW_LOG(mt_listener_mgr_->stop());
ASSERT_TRUE(mt_listener_mgr_->isStopped());
diff --git a/src/lib/tcp/tests/tcp_listener_unittests.cc b/src/lib/tcp/tests/tcp_listener_unittests.cc
index e2b906bae6..e9deff3e8d 100644
--- a/src/lib/tcp/tests/tcp_listener_unittests.cc
+++ b/src/lib/tcp/tests/tcp_listener_unittests.cc
@@ -79,6 +79,13 @@ public:
for (auto const& client : clients_) {
client->close();
}
+
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Create a new client.
diff --git a/src/lib/tcp/tests/tls_listener_unittests.cc b/src/lib/tcp/tests/tls_listener_unittests.cc
index 6b7db45596..c4d1fadf56 100644
--- a/src/lib/tcp/tests/tls_listener_unittests.cc
+++ b/src/lib/tcp/tests/tls_listener_unittests.cc
@@ -74,6 +74,13 @@ public:
for (auto const& client : clients_) {
client->close();
}
+
+ test_timer_.cancel();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Fetch the server TLS context.