From d437aee8f3a3370d76cbc25d2c49d903eb995b7c Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Feb 2013 10:51:58 +0100 Subject: [PATCH] [1924] Get rid of IO test code It isn't used any more and it is complicated, so remove it. --- src/lib/cc/tests/session_unittests.cc | 75 +++------------------------ 1 file changed, 8 insertions(+), 67 deletions(-) diff --git a/src/lib/cc/tests/session_unittests.cc b/src/lib/cc/tests/session_unittests.cc index 0f0fd335e6..0e47d2fa23 100644 --- a/src/lib/cc/tests/session_unittests.cc +++ b/src/lib/cc/tests/session_unittests.cc @@ -29,14 +29,12 @@ #include #include -#include #include #include #include using namespace isc::cc; using std::pair; -using std::vector; using std::list; using std::string; using isc::data::ConstElementPtr; @@ -66,9 +64,6 @@ TEST(AsioSession, establish) { ); } -/// \brief Pair holding header and data of a message sent over the wire. -typedef pair SentMessage; - // 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 @@ -111,53 +106,6 @@ public: socket_.send(asio::buffer(body_wire.data(), body_wire.length())); } - /// \brief Read a message from the socket - /// - /// Read a message from the socket and parse it. Block until it is - /// read or error happens. If error happens, it asio::system_error. - /// - /// This method would block for ever if the sender is not sending. - /// But the whole test has a timeout of 10 seconds (see the - /// SessionTest::SetUp and SessionTest::TearDown). - /// - /// \note The method assumes the wire data are correct and does not check - /// it. Strange things might happen if it is not the case, but the - /// test would likely fail as a result, so we prefer simplicity here. - /// - /// \return Pair containing the header and body elements (in this order). - SentMessage readmsg() { - // The format is: - // - // - // - // - - // Read and convert the lengths first. - uint32_t total_len_data; - uint16_t header_len_data; - vector len_buffers; - len_buffers.push_back(asio::buffer(&total_len_data, - sizeof total_len_data)); - len_buffers.push_back(asio::buffer(&header_len_data, - sizeof header_len_data)); - asio::read(socket_, len_buffers); - const uint32_t total_len = ntohl(total_len_data); - const uint16_t header_len = ntohs(header_len_data); - string header, msg; - header.resize(header_len); - msg.resize(total_len - header_len - sizeof header_len_data); - vector data_buffers; - data_buffers.push_back(asio::buffer(&header[0], header.size())); - data_buffers.push_back(asio::buffer(&msg[0], msg.size())); - asio::read(socket_, data_buffers); - if (msg == "") { // The case of no msg present, for control messages - msg = "null"; - } - // Extract the right data into each string and convert. - return (SentMessage(Element::fromWire(header), - Element::fromWire(msg))); - } - void sendLname() { isc::data::ElementPtr lname_answer1 = isc::data::Element::fromJSON("{ \"type\": \"lname\" }"); @@ -180,6 +128,9 @@ private: char data_buf[1024]; }; +/// \brief Pair holding header and data of a message sent over the connection. +typedef pair SentMessage; + // 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 { @@ -187,6 +138,8 @@ public: TestSession(asio::io_service& ioservice) : Session(ioservice) {} + // Get first message previously sent by sendmsg and remove it from the + // buffer. Expects there's at leas one message in the buffer. SentMessage getSentMessage() { assert(!sent_messages_.empty()); SentMessage result(sent_messages_.front()); @@ -194,6 +147,8 @@ public: return (result); } private: + // Override the sendmsg. They are not sent over the real connection, but + // stored locally and can be extracted by getSentMessage() virtual void sendmsg(ConstElementPtr msg) { sendmsg(msg, ConstElementPtr(new isc::data::NullElement)); } @@ -201,6 +156,7 @@ private: sent_messages_.push_back(SentMessage(env, msg)); } + // The sendmsg stores data here. list sent_messages_; }; @@ -217,21 +173,6 @@ protected: delete tds; } - void SetUp() { - // There are blocking reads in some tests. We want to have a safety - // catch in case the sender didn't write enough. We set a timeout of - // 10 seconds per one test (which should really be enough even on - // slow machines). If the timeout happens, it kills the test and - // the whole test fails. - //alarm(10); - } - - void TearDown() { - // Cancel the timeout scheduled in SetUp. We don't want to kill any - // of the other tests by it by accident. - alarm(0); - } - // Check two elements are equal void elementsEqual(const ConstElementPtr& expected, const ConstElementPtr& actual)