BIND 10 trac1914, updated. 2a723e7e4bfe970673f1ea0a61262d1ba0a475d9 [1924] Don't use real network IO in the test
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Feb 6 16:17:37 UTC 2013
The branch, trac1914 has been updated
via 2a723e7e4bfe970673f1ea0a61262d1ba0a475d9 (commit)
from 6e489c0c04f6682402b594b222095ef50477614e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2a723e7e4bfe970673f1ea0a61262d1ba0a475d9
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Feb 6 17:16:41 2013 +0100
[1924] Don't use real network IO in the test
Mock the low-level sending method and don't rely on network IO to read
it from the other end.
TODO: Remove the support for reading the other end.
-----------------------------------------------------------------------
Summary of changes:
src/lib/cc/session.h | 11 +++++++---
src/lib/cc/tests/session_unittests.cc | 36 +++++++++++++++++++++++++++++----
2 files changed, 40 insertions(+), 7 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/cc/session.h b/src/lib/cc/session.h
index de01c09..64baa73 100644
--- a/src/lib/cc/session.h
+++ b/src/lib/cc/session.h
@@ -166,9 +166,14 @@ namespace isc {
/// @param returns socket descriptor used for session connection
virtual int getSocketDesc() const;
private:
- void sendmsg(isc::data::ConstElementPtr msg);
- void sendmsg(isc::data::ConstElementPtr env,
- isc::data::ConstElementPtr msg);
+ // The following two methods are virtual to allow tests steal and
+ // replace them. It is not expected to be specialized by a derived
+ // class. Actually, it is not expected to inherit from this class
+ // to begin with.
+ virtual void sendmsg(isc::data::ConstElementPtr msg);
+ virtual void sendmsg(isc::data::ConstElementPtr env,
+ isc::data::ConstElementPtr msg);
+
bool recvmsg(isc::data::ConstElementPtr& msg,
bool nonblock = true,
int seq = -1);
diff --git a/src/lib/cc/tests/session_unittests.cc b/src/lib/cc/tests/session_unittests.cc
index eb7101a..0f0fd33 100644
--- a/src/lib/cc/tests/session_unittests.cc
+++ b/src/lib/cc/tests/session_unittests.cc
@@ -30,12 +30,14 @@
#include <utility>
#include <vector>
+#include <list>
#include <string>
#include <iostream>
using namespace isc::cc;
using std::pair;
using std::vector;
+using std::list;
using std::string;
using isc::data::ConstElementPtr;
using isc::data::Element;
@@ -178,6 +180,30 @@ private:
char data_buf[1024];
};
+// We specialize the tested class a little. We replace some low-level
+// methods so we can examine the rest without relying on real network IO
+class TestSession : public Session {
+public:
+ TestSession(asio::io_service& ioservice) :
+ Session(ioservice)
+ {}
+ SentMessage getSentMessage() {
+ assert(!sent_messages_.empty());
+ SentMessage result(sent_messages_.front());
+ sent_messages_.pop_front();
+ return (result);
+ }
+private:
+ virtual void sendmsg(ConstElementPtr msg) {
+ sendmsg(msg, ConstElementPtr(new isc::data::NullElement));
+ }
+ virtual void sendmsg(ConstElementPtr env, ConstElementPtr msg) {
+ sent_messages_.push_back(SentMessage(env, msg));
+ }
+
+ list<SentMessage> sent_messages_;
+};
+
class SessionTest : public ::testing::Test {
protected:
SessionTest() : sess(my_io_service), work(my_io_service) {
@@ -229,7 +255,7 @@ protected:
const char* description)
{
SCOPED_TRACE(description);
- const SentMessage msg(tds->readmsg());
+ const SentMessage &msg(sess.getSentMessage());
elementsEqual(expected_hdr, msg.first);
elementsEqual("{\"test\": 42}", msg.second);
}
@@ -256,7 +282,7 @@ public:
protected:
asio::io_service my_io_service;
TestDomainSocket* tds;
- Session sess;
+ TestSession sess;
// Keep run() from stopping right away by informing it it has work to do
asio::io_service::work work;
};
@@ -352,10 +378,12 @@ TEST_F(SessionTest, get_socket_descr) {
// Test the group_sendmsg sends the correct data.
TEST_F(SessionTest, group_sendmsg) {
- // Connect
+ // Connect (to set the lname, so we can see it sets the from)
tds->setSendLname();
sess.establish(BIND10_TEST_SOCKET_FILE);
- elementsEqual("{\"type\": \"getlname\"}", tds->readmsg().first);
+ // Eat the "get_lname" message, so it doesn't confuse the
+ // test below.
+ sess.getSentMessage();
const ConstElementPtr msg(Element::fromJSON("{\"test\": 42}"));
sess.group_sendmsg(msg, "group");
More information about the bind10-changes
mailing list