BIND 10 master, updated. d94641e52198629abdd3ffe82751b0b6ce11ff28 [master] Merge branch 'trac2621'

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Jan 28 12:41:39 UTC 2013


The branch, master has been updated
       via  d94641e52198629abdd3ffe82751b0b6ce11ff28 (commit)
       via  d8c2ea58e026b76c516f7ff6e3d6199af1b5ecc7 (commit)
      from  6873aeabcd152ef491fa66b1292192e1c16e1215 (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 d94641e52198629abdd3ffe82751b0b6ce11ff28
Merge: 6873aea d8c2ea5
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Jan 28 13:41:29 2013 +0100

    [master] Merge branch 'trac2621'

commit d8c2ea58e026b76c516f7ff6e3d6199af1b5ecc7
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Jan 28 13:41:13 2013 +0100

    [2621] Fix session_test for python3.3
    
    Or more specifically, make the tests not depend on dict ordering

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

Summary of changes:
 src/lib/python/isc/cc/tests/session_test.py |  116 ++++++++++++++++++---------
 1 file changed, 76 insertions(+), 40 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/cc/tests/session_test.py b/src/lib/python/isc/cc/tests/session_test.py
index e589085..e8656e7 100644
--- a/src/lib/python/isc/cc/tests/session_test.py
+++ b/src/lib/python/isc/cc/tests/session_test.py
@@ -19,6 +19,7 @@
 
 import unittest
 import os
+import json
 from isc.cc.session import *
 
 # our fake socket, where we can read and insert messages
@@ -73,8 +74,23 @@ class MySocket():
 
         result.extend(self.readsent(header_length))
         result.extend(self.readsent(data_length))
+
         return result
 
+    def readsentmsg_parsed(self):
+        length_buf = self.readsent(4)
+        length = struct.unpack('>I', length_buf)[0]
+        header_length_buf = self.readsent(2)
+        header_length = struct.unpack('>H', header_length_buf)[0]
+        data_length = length - 2 - header_length
+
+        env = json.loads(self.readsent(header_length).decode('utf-8'), strict=False)
+        if (data_length > 0):
+            msg = json.loads(self.readsent(data_length).decode('utf-8'), strict=False)
+        else:
+            msg = {}
+        return (env, msg)
+
     def recv(self, length):
         if len(self.recvqueue) == 0:
             if self._blocking:
@@ -208,25 +224,25 @@ class testSession(unittest.TestCase):
 
         # 'malformed' messages
         # shouldn't some of these raise exceptions?
-        #self.recv_and_compare(sess, 
+        #self.recv_and_compare(sess,
         #                      b'\x00',
         #                      None, None)
-        #self.recv_and_compare(sess, 
+        #self.recv_and_compare(sess,
         #                      b'\x00\x00\x00\x10',
         #                      None, None)
-        #self.recv_and_compare(sess, 
+        #self.recv_and_compare(sess,
         #                      b'\x00\x00\x00\x02\x00\x00',
         #                      None, None)
-        #self.recv_and_compare(sess, 
+        #self.recv_and_compare(sess,
         #                      b'\x00\x00\x00\x02\x00\x02',
         #                      None, None)
-        #self.recv_and_compare(sess, 
+        #self.recv_and_compare(sess,
         #                      b'',
         #                      None, None)
 
         # need to clear
         sess._socket.recvqueue = bytearray()
-        
+
         # 'queueing' system
         # sending message {'to': 'someone', 'reply': 1}, {"hello": "a"}
         #print("sending message {'to': 'someone', 'reply': 1}, {'hello': 'a'}")
@@ -240,7 +256,7 @@ class testSession(unittest.TestCase):
         self.assertEqual({'to': 'someone', 'reply': 1}, env)
         self.assertEqual({"hello": "a"}, msg)
         self.assertFalse(sess.has_queued_msgs())
-        
+
         # ask for a differe sequence number reply (that doesn't exist)
         # then ask for the one that is there
         self.assertFalse(sess.has_queued_msgs())
@@ -253,7 +269,7 @@ class testSession(unittest.TestCase):
         self.assertEqual({'to': 'someone', 'reply': 1}, env)
         self.assertEqual({"hello": "a"}, msg)
         self.assertFalse(sess.has_queued_msgs())
-        
+
         # ask for a differe sequence number reply (that doesn't exist)
         # then ask for any message
         self.assertFalse(sess.has_queued_msgs())
@@ -266,7 +282,7 @@ class testSession(unittest.TestCase):
         self.assertEqual({'to': 'someone', 'reply': 1}, env)
         self.assertEqual({"hello": "a"}, msg)
         self.assertFalse(sess.has_queued_msgs())
-        
+
         #print("sending message {'to': 'someone', 'reply': 1}, {'hello': 'a'}")
 
         # ask for a differe sequence number reply (that doesn't exist)
@@ -287,7 +303,7 @@ class testSession(unittest.TestCase):
         self.assertEqual({'to': 'someone'}, env)
         self.assertEqual({"hello": "b"}, msg)
         self.assertFalse(sess.has_queued_msgs())
-        
+
         # send a message, then one with specific reply value
         # ask for that specific message (get the second)
         # then ask for any message (get the first)
@@ -326,48 +342,56 @@ class testSession(unittest.TestCase):
     def test_group_subscribe(self):
         sess = MySession()
         sess.group_subscribe("mygroup")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00<\x00:{"group": "mygroup", "type": "subscribe", "instance": "*"}')
-        
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"group": "mygroup", "type": "subscribe",
+                                 "instance": "*"}, {}))
+
         sess.group_subscribe("mygroup")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00<\x00:{"group": "mygroup", "type": "subscribe", "instance": "*"}')
-        
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"group": "mygroup", "type": "subscribe",
+                                 "instance": "*"}, {}))
+
         sess.group_subscribe("mygroup", "my_instance")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00F\x00D{"group": "mygroup", "type": "subscribe", "instance": "my_instance"}')
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"group": "mygroup", "type": "subscribe",
+                                 "instance": "my_instance"}, {}))
 
     def test_group_unsubscribe(self):
         sess = MySession()
         sess.group_unsubscribe("mygroup")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00>\x00<{"group": "mygroup", "type": "unsubscribe", "instance": "*"}')
-        
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"group": "mygroup", "type": "unsubscribe",
+                                 "instance": "*"}, {}))
+
         sess.group_unsubscribe("mygroup")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00>\x00<{"group": "mygroup", "type": "unsubscribe", "instance": "*"}')
-        
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"group": "mygroup", "type": "unsubscribe",
+                                 "instance": "*"}, {}))
+
         sess.group_unsubscribe("mygroup", "my_instance")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00H\x00F{"group": "mygroup", "type": "unsubscribe", "instance": "my_instance"}')
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"group": "mygroup", "type": "unsubscribe",
+                                 "instance": "my_instance"}, {}))
 
     def test_group_sendmsg(self):
         sess = MySession()
         self.assertEqual(sess._sequence, 1)
 
         sess.group_sendmsg({ 'hello': 'a' }, "my_group")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00p\x00`{"from": "test_name", "seq": 2, "to": "*", "instance": "*", "group": "my_group", "type": "send"}{"hello": "a"}')
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"from": "test_name", "seq": 2, "to": "*",
+                                 "instance": "*", "group": "my_group",
+                                 "type": "send"}, {"hello": "a"}))
         self.assertEqual(sess._sequence, 2)
 
         sess.group_sendmsg({ 'hello': 'a' }, "my_group", "my_instance")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00z\x00j{"from": "test_name", "seq": 3, "to": "*", "instance": "my_instance", "group": "my_group", "type": "send"}{"hello": "a"}')
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"from": "test_name", "seq": 3, "to": "*", "instance": "my_instance", "group": "my_group", "type": "send"}, {"hello": "a"}))
         self.assertEqual(sess._sequence, 3)
-        
+
         sess.group_sendmsg({ 'hello': 'a' }, "your_group", "your_instance")
-        sent = sess._socket.readsentmsg()
-        self.assertEqual(sent, b'\x00\x00\x00~\x00n{"from": "test_name", "seq": 4, "to": "*", "instance": "your_instance", "group": "your_group", "type": "send"}{"hello": "a"}')
+        sent = sess._socket.readsentmsg_parsed()
+        self.assertEqual(sent, ({"from": "test_name", "seq": 4, "to": "*", "instance": "your_instance", "group": "your_group", "type": "send"}, {"hello": "a"}))
         self.assertEqual(sess._sequence, 4)
 
     def test_group_recvmsg(self):
@@ -377,13 +401,25 @@ class testSession(unittest.TestCase):
 
     def test_group_reply(self):
         sess = MySession()
-        sess.group_reply({ 'from': 'me', 'group': 'our_group', 'instance': 'other_instance', 'seq': 4}, {"hello": "a"})
-        sent = sess._socket.readsentmsg();
-        self.assertEqual(sent, b'\x00\x00\x00\x8b\x00{{"from": "test_name", "seq": 2, "to": "me", "instance": "other_instance", "reply": 4, "group": "our_group", "type": "send"}{"hello": "a"}')
-        
-        sess.group_reply({ 'from': 'me', 'group': 'our_group', 'instance': 'other_instance', 'seq': 9}, {"hello": "a"})
-        sent = sess._socket.readsentmsg();
-        self.assertEqual(sent, b'\x00\x00\x00\x8b\x00{{"from": "test_name", "seq": 3, "to": "me", "instance": "other_instance", "reply": 9, "group": "our_group", "type": "send"}{"hello": "a"}')
+        sess.group_reply({ 'from': 'me', 'group': 'our_group',
+                           'instance': 'other_instance', 'seq': 4},
+                         {"hello": "a"})
+        sent = sess._socket.readsentmsg_parsed();
+        self.assertEqual(sent, ({"from": "test_name", "seq": 2,
+                                 "to": "me", "instance": "other_instance",
+                                 "reply": 4, "group": "our_group",
+                                 "type": "send"},
+                                {"hello": "a"}))
+
+        sess.group_reply({ 'from': 'me', 'group': 'our_group',
+                           'instance': 'other_instance', 'seq': 9},
+                         {"hello": "a"})
+        sent = sess._socket.readsentmsg_parsed();
+        self.assertEqual(sent, ({"from": "test_name", "seq": 3,
+                                 "to": "me", "instance": "other_instance",
+                                 "reply": 9, "group": "our_group",
+                                 "type": "send"},
+                                {"hello": "a"}))
 
     def test_timeout(self):
         if "BIND10_TEST_SOCKET_FILE" not in os.environ:



More information about the bind10-changes mailing list