mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
update other 'fake' session implementations to new interface
use build-dir based domain socket for tests (requires clean rebuild to generate .h file) git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac296@2650 e5f2f494-b856-4b98-b285-d166d9295462
This commit is contained in:
@@ -473,6 +473,7 @@ AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py
|
||||
src/lib/python/bind10_config.py
|
||||
src/lib/dns/tests/testdata/gen-wiredata.py
|
||||
src/lib/cc/session_config.h.pre
|
||||
src/lib/cc/session_unittests_config.h
|
||||
], [
|
||||
chmod +x src/bin/cmdctl/run_b10-cmdctl.sh
|
||||
chmod +x src/bin/xfrin/run_b10-xfrin.sh
|
||||
|
@@ -94,6 +94,8 @@ private:
|
||||
virtual void startRead(boost::function<void()> read_callback);
|
||||
virtual int reply(ElementPtr& envelope, ElementPtr& newmsg);
|
||||
virtual bool hasQueuedMsgs();
|
||||
virtual void setTimeout(size_t timeout UNUSED_PARAM) {};
|
||||
virtual size_t getTimeout() { return 0; };
|
||||
|
||||
void setMessage(ElementPtr msg) { msg_ = msg; }
|
||||
void disableSend() { send_ok_ = false; }
|
||||
|
@@ -30,6 +30,8 @@
|
||||
#include <asio.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "session_unittests_config.h"
|
||||
|
||||
using namespace isc::cc;
|
||||
|
||||
TEST(AsioSession, establish) {
|
||||
@@ -109,6 +111,10 @@ private:
|
||||
};
|
||||
*/
|
||||
|
||||
// This class sets up a domain socket for the session to connect to
|
||||
// it will impersonate the msgq a tiny bit (if setSendLname() has
|
||||
// been called, it will send an 'answer' to the lname query that is
|
||||
// sent in the initialization of Session objects)
|
||||
class TestDomainSocket {
|
||||
|
||||
public:
|
||||
@@ -124,6 +130,7 @@ public:
|
||||
|
||||
~TestDomainSocket() {
|
||||
socket_.close();
|
||||
::unlink(BIND10_TEST_SOCKET_FILE);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -169,40 +176,39 @@ private:
|
||||
|
||||
TEST(Session, timeout_on_connect) {
|
||||
asio::io_service my_io_service;
|
||||
::unlink("/tmp/mysock.sock");
|
||||
TestDomainSocket tds(my_io_service, "/tmp/mysock.sock");
|
||||
::unlink(BIND10_TEST_SOCKET_FILE);
|
||||
TestDomainSocket tds(my_io_service, BIND10_TEST_SOCKET_FILE);
|
||||
Session sess(my_io_service);
|
||||
// set to a short timeout so the test doesn't take too long
|
||||
EXPECT_EQ(4000, sess.getTimeout());
|
||||
sess.setTimeout(100);
|
||||
EXPECT_EQ(100, sess.getTimeout());
|
||||
// no answer, should timeout
|
||||
EXPECT_THROW(sess.establish("/tmp/mysock.sock"), isc::cc::SessionTimeout);
|
||||
EXPECT_THROW(sess.establish(BIND10_TEST_SOCKET_FILE), isc::cc::SessionTimeout);
|
||||
}
|
||||
|
||||
TEST(Session, connect_ok) {
|
||||
asio::io_service my_io_service;
|
||||
::unlink("/tmp/mysock.sock");
|
||||
TestDomainSocket tds(my_io_service, "/tmp/mysock.sock");
|
||||
::unlink(BIND10_TEST_SOCKET_FILE);
|
||||
TestDomainSocket tds(my_io_service, BIND10_TEST_SOCKET_FILE);
|
||||
tds.setSendLname();
|
||||
|
||||
Session sess(my_io_service);
|
||||
sess.establish("/tmp/mysock.sock");
|
||||
sess.establish(BIND10_TEST_SOCKET_FILE);
|
||||
}
|
||||
|
||||
TEST(Session, connect_ok2) {
|
||||
TEST(Session, connect_ok_connection_reset) {
|
||||
asio::io_service my_io_service;
|
||||
::unlink("/tmp/mysock.sock");
|
||||
::unlink(BIND10_TEST_SOCKET_FILE);
|
||||
Session sess(my_io_service);
|
||||
|
||||
// Create a fake socket in a smaller scope, so we can
|
||||
// Create a fake msgq in a smaller scope, so we can
|
||||
// connect the session to it, but later calls on the
|
||||
// underlying socket will fail
|
||||
{
|
||||
TestDomainSocket tds(my_io_service, "/tmp/mysock.sock");
|
||||
TestDomainSocket tds(my_io_service, BIND10_TEST_SOCKET_FILE);
|
||||
tds.setSendLname();
|
||||
|
||||
sess.establish("/tmp/mysock.sock");
|
||||
sess.establish(BIND10_TEST_SOCKET_FILE);
|
||||
}
|
||||
|
||||
isc::data::ElementPtr env, msg;
|
||||
|
2
src/lib/cc/session_unittests_config.h.in
Normal file
2
src/lib/cc/session_unittests_config.h.in
Normal file
@@ -0,0 +1,2 @@
|
||||
#define BIND10_TEST_SOCKET_FILE "@builddir@/test_socket.sock"
|
||||
|
@@ -72,6 +72,8 @@ public:
|
||||
virtual int reply(isc::data::ElementPtr& envelope,
|
||||
isc::data::ElementPtr& newmsg);
|
||||
virtual bool hasQueuedMsgs();
|
||||
virtual void setTimeout(size_t milliseconds) {};
|
||||
virtual size_t getTimeout() { return 0; };
|
||||
isc::data::ElementPtr getFirstMessage(std::string& group, std::string& to);
|
||||
void addMessage(isc::data::ElementPtr, const std::string& group,
|
||||
const std::string& to);
|
||||
|
Reference in New Issue
Block a user