BIND 10 trac1914, updated. 8a17ce75a1d3287785c9d0234f3e4c82232a39ea [1924] Reuse similar test code

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Feb 7 12:29:24 UTC 2013


The branch, trac1914 has been updated
       via  8a17ce75a1d3287785c9d0234f3e4c82232a39ea (commit)
       via  880db2ba394a9dbe0133f5e4730ae4b99f6bd20b (commit)
       via  60b36bdabd4c052e5afaebc1a0d2ddd8eab637c2 (commit)
      from  d437aee8f3a3370d76cbc25d2c49d903eb995b7c (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 8a17ce75a1d3287785c9d0234f3e4c82232a39ea
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Feb 7 13:01:05 2013 +0100

    [1924] Reuse similar test code

commit 880db2ba394a9dbe0133f5e4730ae4b99f6bd20b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Feb 7 11:07:16 2013 +0100

    [1924] Pydoc comment for the group_sendmsg method.

commit 60b36bdabd4c052e5afaebc1a0d2ddd8eab637c2
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Feb 7 10:59:53 2013 +0100

    [1924] Combine the elementsEqual variants together
    
    One of them is a relict of previous tests and is no longer needed, so
    have only one.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/cc/tests/session_unittests.cc       |   14 ++----
 src/lib/python/isc/cc/session.py            |   18 +++++++
 src/lib/python/isc/cc/tests/session_test.py |   68 ++++++++++++---------------
 3 files changed, 51 insertions(+), 49 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/cc/tests/session_unittests.cc b/src/lib/cc/tests/session_unittests.cc
index 0e47d2f..8859bfb 100644
--- a/src/lib/cc/tests/session_unittests.cc
+++ b/src/lib/cc/tests/session_unittests.cc
@@ -174,20 +174,12 @@ protected:
     }
 
     // Check two elements are equal
-    void elementsEqual(const ConstElementPtr& expected,
-                       const ConstElementPtr& actual)
-    {
-        EXPECT_TRUE(expected->equals(*actual)) <<
-            "Elements differ, expected: " << expected->toWire() <<
-            ", got: " << actual->toWire();
-    }
-
-    // The same, but with one specified as string
     void elementsEqual(const string& expected,
                        const ConstElementPtr& actual)
     {
-        const ConstElementPtr expected_el(Element::fromJSON(expected));
-        elementsEqual(expected_el, actual);
+        EXPECT_TRUE(Element::fromJSON(expected)->equals(*actual)) <<
+            "Elements differ, expected: " << expected <<
+            ", got: " << actual->toWire();
     }
 
     // Check the session sent a message with the given header. The
diff --git a/src/lib/python/isc/cc/session.py b/src/lib/python/isc/cc/session.py
index cfc54d9..976bfc5 100644
--- a/src/lib/python/isc/cc/session.py
+++ b/src/lib/python/isc/cc/session.py
@@ -259,6 +259,24 @@ class Session:
 
     def group_sendmsg(self, msg, group, instance=CC_INSTANCE_WILDCARD,
                       to=CC_TO_WILDCARD, want_answer=False):
+        '''
+        Send a message over the CC session.
+
+        Parameters:
+        - msg The message to send, encoded as python structures (dicts,
+          lists, etc).
+        - group The recipient group to send to.
+        - instance Instance in the group.
+        - to Direct recipient (overrides the above, should contain the
+          lname of the recipient).
+        - want_answer If an answer is requested. If there's no recipient,
+          the message queue would send an error message instead of the
+          answer.
+
+        Return:
+          A sequence number that can be used to wait for an answer
+          (see group_recvmsg).
+        '''
         seq = self._next_sequence()
         self.sendmsg({
             CC_HEADER_TYPE: CC_COMMAND_SEND,
diff --git a/src/lib/python/isc/cc/tests/session_test.py b/src/lib/python/isc/cc/tests/session_test.py
index 05caf0a..8de1e96 100644
--- a/src/lib/python/isc/cc/tests/session_test.py
+++ b/src/lib/python/isc/cc/tests/session_test.py
@@ -377,46 +377,38 @@ class testSession(unittest.TestCase):
         sess = MySession()
         self.assertEqual(sess._sequence, 1)
 
-        sess.group_sendmsg({ 'hello': 'a' }, "my_group")
-        sent = sess._socket.readsentmsg_parsed()
-        self.assertEqual(sent, ({"from": "test_name", "seq": 2, "to": "*",
-                                 "instance": "*", "group": "my_group",
-                                 "type": "send", "want_answer": False},
-                                {"hello": "a"}))
-        self.assertEqual(sess._sequence, 2)
+        msg = { "hello": "a" }
+
+        def check_sent(additional_headers, sequence):
+            sent = sess._socket.readsentmsg_parsed()
+            headers = dict({"from": "test_name",
+                            "seq": sequence,
+                            "to": "*",
+                            "type": "send"},
+                           **additional_headers)
+            self.assertEqual(sent, (headers, msg))
+            self.assertEqual(sess._sequence, sequence)
+
+        sess.group_sendmsg(msg, "my_group")
+        check_sent({"instance": "*", "group": "my_group",
+                    "want_answer": False}, 2)
+
+        sess.group_sendmsg(msg, "my_group", "my_instance")
+        check_sent({"instance": "my_instance", "group": "my_group",
+                    "want_answer": False}, 3)
+
+        sess.group_sendmsg(msg, "your_group", "your_instance")
+        check_sent({"instance": "your_instance", "group": "your_group",
+                    "want_answer": False}, 4)
 
-        sess.group_sendmsg({ 'hello': 'a' }, "my_group", "my_instance")
-        sent = sess._socket.readsentmsg_parsed()
-        self.assertEqual(sent, ({"from": "test_name", "seq": 3, "to": "*",
-                                 "instance": "my_instance",
-                                 "group": "my_group", "type": "send",
-                                 "want_answer": False},
-                                {"hello": "a"}))
-        self.assertEqual(sess._sequence, 3)
-
-        sess.group_sendmsg({ 'hello': 'a' }, "your_group", "your_instance")
-        sent = sess._socket.readsentmsg_parsed()
-        self.assertEqual(sent, ({"from": "test_name", "seq": 4, "to": "*",
-                                 "instance": "your_instance",
-                                 "group": "your_group", "type": "send",
-                                 "want_answer": False},
-                                {"hello": "a"}))
-        self.assertEqual(sess._sequence, 4)
         # Test the optional want_answer parameter
-        sess.group_sendmsg({'hello': 'a'}, "group", want_answer=True)
-        sent = sess._socket.readsentmsg_parsed()
-        self.assertEqual(sent, ({"from": "test_name", "seq": 5, "to": "*",
-                                 "instance": "*", "group": "group", "type":
-                                 "send", "want_answer": True},
-                                {"hello": "a"}))
-        self.assertEqual(sess._sequence, 5)
-        sess.group_sendmsg({'hello': 'a'}, "group", want_answer=False)
-        sent = sess._socket.readsentmsg_parsed()
-        self.assertEqual(sent, ({"from": "test_name", "seq": 6, "to": "*",
-                                 "instance": "*", "group": "group", "type":
-                                 "send", "want_answer": False},
-                                {"hello": "a"}))
-        self.assertEqual(sess._sequence, 6)
+        sess.group_sendmsg(msg, "group", want_answer=True)
+        check_sent({"instance": "*", "group": "group", "want_answer": True}, 5)
+
+
+        sess.group_sendmsg(msg, "group", want_answer=False)
+        check_sent({"instance": "*", "group": "group", "want_answer": False},
+                   6)
 
     def test_group_recvmsg(self):
         # must this one do anything except not return messages with



More information about the bind10-changes mailing list