BIND 10 trac2922, updated. 84d7b7a1804acdb5eeaf96b36940676227856110 [2822] Test getting list of group/msgq members
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed May 29 14:23:52 UTC 2013
The branch, trac2922 has been updated
via 84d7b7a1804acdb5eeaf96b36940676227856110 (commit)
via eb5a53e0b7144be371c918fbe890d61c2f7bb6ee (commit)
from 42d2c5dd25db24de34ca7ac998d60478b52e4536 (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 84d7b7a1804acdb5eeaf96b36940676227856110
Author: Michal 'vorner' Vaner <vorner at vorner.cz>
Date: Wed May 29 16:23:27 2013 +0200
[2822] Test getting list of group/msgq members
commit eb5a53e0b7144be371c918fbe890d61c2f7bb6ee
Author: Michal 'vorner' Vaner <vorner at vorner.cz>
Date: Wed May 29 15:50:30 2013 +0200
[2822] Keep mapping from fd to lname
It'll be needed in the following work.
-----------------------------------------------------------------------
Summary of changes:
src/bin/msgq/msgq.py.in | 5 +++-
src/bin/msgq/tests/msgq_test.py | 63 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 66 insertions(+), 2 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/msgq/msgq.py.in b/src/bin/msgq/msgq.py.in
index efa3cbd..bd77cf2 100755
--- a/src/bin/msgq/msgq.py.in
+++ b/src/bin/msgq/msgq.py.in
@@ -184,6 +184,7 @@ class MsgQ:
self.hostname = socket.gethostname()
self.subs = SubscriptionManager(self.cfgmgr_ready)
self.lnames = {}
+ self.fd_to_lname = {}
self.sendbuffs = {}
self.running = False
self.__cfgmgr_ready = None
@@ -328,6 +329,7 @@ class MsgQ:
self.sockets[newsocket.fileno()] = newsocket
lname = self.newlname()
self.lnames[lname] = newsocket
+ self.fd_to_lname[newsocket.fileno()] = lname
logger.debug(TRACE_BASIC, MSGQ_SOCKET_REGISTERED, newsocket.fileno(),
lname)
@@ -346,7 +348,8 @@ class MsgQ:
self.poller.unregister(sock)
self.subs.unsubscribe_all(sock)
- lname = [ k for k, v in self.lnames.items() if v == sock ][0]
+ lname = self.fd_to_lname[fd]
+ del self.fd_to_lname[fd]
del self.lnames[lname]
sock.close()
del self.sockets[fd]
diff --git a/src/bin/msgq/tests/msgq_test.py b/src/bin/msgq/tests/msgq_test.py
index e248b10..5ae10d9 100644
--- a/src/bin/msgq/tests/msgq_test.py
+++ b/src/bin/msgq/tests/msgq_test.py
@@ -187,6 +187,55 @@ class MsgQTest(unittest.TestCase):
self.assertEqual({'result': [1, "unknown command: unknown"]},
self.__msgq.command_handler('unknown', {}))
+ def test_get_members(self):
+ """
+ Test getting members of a group or of all connected clients.
+ """
+ # Push two dummy "clients" into msgq (the ugly way, by directly
+ # tweaking relevant data structures).
+ class Sock:
+ def __init__(self, fileno):
+ self.fileno = lambda: fileno
+ self.__msgq.lnames["first"] = Sock(1)
+ self.__msgq.lnames["second"] = Sock(2)
+ self.__msgq.fd_to_lname[1] = "first"
+ self.__msgq.fd_to_lname[2] = "second"
+ # Subscribe them to some groups
+ self.__msgq.process_command_subscribe(self.__msgq.lnames["first"],
+ {'group': "G1", 'instance': "*"},
+ None)
+ self.__msgq.process_command_subscribe(self.__msgq.lnames["second"],
+ {'group': "G1", 'instance': "*"},
+ None)
+ self.__msgq.process_command_subscribe(self.__msgq.lnames["second"],
+ {'group': "G2", 'instance': "*"},
+ None)
+ # Now query content of some groups through the command handler.
+ self.__msgq.running = True # Enable the command handler
+ def check_both(result):
+ """
+ Check the result is successful one and it contains both lnames (in
+ any order).
+ """
+ array = result['result'][1]
+ self.assertEqual(set(['first', 'second']), array)
+ self.assertEqual({'result': [0, array]}, array)
+ # Members of the G1 and G2
+ self.assertEqual({'result': [0, ["second"]]},
+ self.__msgq.command_handler('members',
+ {'group': "G2"}))
+ check_both(self.__msgq.command_handler('members', {'group': 'G1'}))
+ # We pretend that all the possible groups exist, just that most
+ # of them are empty. So requesting for G3 is request for an empty
+ # group and should not fail.
+ self.assertEqual({'result': [0, []]},
+ self.__msgq.command_handler('members',
+ {'group': "Empty"}))
+ # Without the name of the group, we just get all the clients.
+ check_both(self.__msgq.command_handler('members', {}))
+ # Omitting the parameters completely in such case is OK
+ check_both(self.__msgq.command_handler('members', None))
+
def test_undeliverable_errors(self):
"""
Send several packets through the MsgQ and check it generates
@@ -421,12 +470,17 @@ class SendNonblock(unittest.TestCase):
The write end is put into the message queue, so we can check it.
It returns (msgq, read_end, write_end). It is expected the sockets
are closed by the caller afterwards.
+
+ Also check the sockets are registered correctly (eg. internal data
+ structures are there for them).
'''
msgq = MsgQ()
# We do only partial setup, so we don't create the listening socket
msgq.setup_poller()
(read, write) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
msgq.register_socket(write)
+ self.assertEqual(1, len(msgq.lnames))
+ self.assertEqual(write, msgq.lnames[msgq.fd_to_lname[write.fileno()]])
return (msgq, read, write)
def infinite_sender(self, sender):
@@ -446,8 +500,15 @@ class SendNonblock(unittest.TestCase):
# Explicitly close temporary socket pair as the Python
# interpreter expects it. It may not be 100% exception safe,
# but since this is only for tests we prefer brevity.
+ # Actually, the write end is often closed by the sender.
+ if write.fileno() != -1:
+ # Some of the senders passed here kill the socket internally.
+ # So kill it only if not yet done so. If the socket is closed,
+ # it gets -1 as fileno().
+ msgq.kill_socket(write.fileno(), write)
+ self.assertFalse(msgq.lnames)
+ self.assertFalse(msgq.fd_to_lname)
read.close()
- write.close()
def test_infinite_sendmsg(self):
"""
More information about the bind10-changes
mailing list