BIND 10 trac2353, updated. fa3e24bb027671b5c53a5fa1b004920cf8252f0f [2353] Test BoB._socket_data() directly

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Nov 19 22:05:41 UTC 2012


The branch, trac2353 has been updated
       via  fa3e24bb027671b5c53a5fa1b004920cf8252f0f (commit)
       via  a11abf30b29eda75f8680c8287b57db1abe612e8 (commit)
      from  996d6ff3b0e79c723332d03296cbbe88b552d373 (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 fa3e24bb027671b5c53a5fa1b004920cf8252f0f
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Nov 20 03:34:56 2012 +0530

    [2353] Test BoB._socket_data() directly

commit a11abf30b29eda75f8680c8287b57db1abe612e8
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Nov 20 03:34:32 2012 +0530

    [2353] Indent comment

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

Summary of changes:
 src/bin/bind10/tests/bind10_test.py.in |   58 +++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index a111cbc..8672e52 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -1620,7 +1620,8 @@ class TestBossComponents(unittest.TestCase):
         # We just check that an exception was thrown, and that several
         # attempts were made to connect.
         self.assertTrue(thrown)
-        # 1 second of attempts every 0.1 seconds should result in at least 5 attempts
+        # 1 second of attempts every 0.1 seconds should result in at
+        # least 5 attempts
         self.assertGreater(attempts, 5)
 
         time.time = tmp_time
@@ -1848,6 +1849,61 @@ class TestBossComponents(unittest.TestCase):
         self.assertEqual('b10-cmdctl', bob.started_process_name)
         self.assertEqual(['b10-cmdctl', '--port=9353', '-v'], bob.started_process_args)
 
+    def test_socket_data(self):
+        '''Test that BoB._socket_data works as expected.'''
+        class MockSock:
+            def __init__(self, fd, throw):
+                self.fd = fd
+                self.throw = throw
+                self.buf = b'Hello World.\nYou are so nice today.\nXX'
+                self.i = 0
+
+            def recv(self, bufsize, flags = 0):
+                if bufsize != 1:
+                    raise Exception('bufsize != 1')
+                if flags != socket.MSG_DONTWAIT:
+                    raise Exception('flags != socket.MSG_DONTWAIT')
+                if self.throw and self.i > 15:
+                    raise socket.error(errno.EAGAIN, 'Try again')
+                if self.i >= len(self.buf):
+                    return b'';
+                t = self.i
+                self.i += 1
+                return self.buf[t:t+1]
+
+            def close(self):
+                return
+
+        class MockBobSocketData(BoB):
+            def __init__(self, throw):
+                self._unix_sockets = {42: (MockSock(42, throw), b'')}
+                self.requests = []
+                self.dead = []
+
+            def socket_request_handler(self, previous, sock):
+                self.requests.append({sock.fd: previous})
+
+            def socket_consumer_dead(self, sock):
+                self.dead.append(sock.fd)
+
+        # All is well case
+        bob = MockBobSocketData(False)
+        bob._socket_data(42)
+        self.assertEqual(bob.requests,
+                         [{42: b'Hello World.'},
+                          {42: b'You are so nice today.'}])
+        self.assertEqual(bob.dead, [42])
+        self.assertFalse(bob._unix_sockets)
+
+        # Case where socket raises EAGAIN. In this case, the routine is
+        # supposed to save what it has back to BoB._unix_sockets.
+        bob = MockBobSocketData(True)
+        bob._socket_data(42)
+        self.assertEqual(bob.requests, [{42: b'Hello World.'}])
+        self.assertFalse(bob.dead)
+        self.assertEqual(len(bob._unix_sockets), 1)
+        self.assertEqual(bob._unix_sockets[42][1], b'You')
+
 class SocketSrvTest(unittest.TestCase):
     """
     This tests some methods of boss related to the unix domain sockets used



More information about the bind10-changes mailing list