From: Michal 'vorner' Vaner Date: Fri, 31 May 2013 08:17:10 +0000 (+0200) Subject: [2922] Test it tries to send the notifications X-Git-Tag: bind10-1.2.0beta1-release~406^2~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a8186631e5cd811b2ebf8df6d837182ea39177ea;p=thirdparty%2Fkea.git [2922] Test it tries to send the notifications --- diff --git a/src/bin/msgq/tests/msgq_test.py b/src/bin/msgq/tests/msgq_test.py index d79ea8a0e5..d968763f5b 100644 --- a/src/bin/msgq/tests/msgq_test.py +++ b/src/bin/msgq/tests/msgq_test.py @@ -240,6 +240,58 @@ class MsgQTest(unittest.TestCase): # Omitting the parameters completely in such case is OK check_both(self.__msgq.command_handler('members', None)) + def test_notifies(self): + """ + Test the message queue sends notifications about connecting, + disconnecting and subscription changes. + """ + # Mock the method to send notifications (we don't really want + # to send them now, just see they'd be sent). + # Mock the poller, as we don't need it at all (and we don't have + # real socket to give it now). + notifications = [] + def send_notification(event, params): + notifications.append((event, params)) + class FakePoller: + def register(self, socket, mode): + pass + def unregister(self, fd, sock): + pass + self.__msgq.members_notify = send_notification + self.__msgq.poller = FakePoller() + + # Create a socket + class Sock: + def __init__(self, fileno): + self.fileno = lambda: fileno + sock = Sock(1) + + # We should notify about new cliend when we register it + self.__msgq.register_socket(sock) + lname = list(self.__msgq.lnames.keys())[0] # Steal the lname + self.assertEqual([('connected', {'client': lname})], notifications) + notifications.clear() + + # A notification should happen for a subscription to a group + self.__msgq.process_command_subscribe(sock, {'group': 'G', + 'instance': '*'}, + None) + self.assertEqual([('subscribed', {'client': lname, 'group': 'G'})], + notifications) + notifications.clear() + + # As well for unsubscription + self.__msgq.process_command_unsubscribe(sock, {'group': 'G', + 'instance': '*'}, + None) + self.assertEqual([('unsubscribed', {'client': lname, 'group': 'G'})], + notifications) + notifications.clear() + + # And, finally, for removal of client + self.__msgq.kill_socket(sock.fileno(), sock) + self.assertEqual([('disconnected', {'client': lname})], notifications) + def test_undeliverable_errors(self): """ Send several packets through the MsgQ and check it generates