|
@@ -272,6 +272,58 @@ class MsgqRunTest(unittest.TestCase):
|
|
|
conn.close()
|
|
|
conn = new
|
|
|
|
|
|
+ def test_notifications(self):
|
|
|
+ """
|
|
|
+ Check that the MsgQ is actually sending notifications about events.
|
|
|
+ We create a socket, subscribe the socket itself and see it receives
|
|
|
+ it's own notification.
|
|
|
+
|
|
|
+ Testing all the places where notifications happen is task for the
|
|
|
+ common unit tests in msgq_test.py.
|
|
|
+
|
|
|
+ The test is here, because there might be some trouble with multiple
|
|
|
+ threads in msgq which would be hard to test using pure unit tests.
|
|
|
+ """
|
|
|
+ conn = self.__get_connection()
|
|
|
+
|
|
|
+ conn.group_subscribe("ConfigManager")
|
|
|
+
|
|
|
+ (msg, env) = conn.group_recvmsg(nonblock=False)
|
|
|
+ self.assertEqual({'command': ['get_config',
|
|
|
+ {'module_name': 'Logging'}]},
|
|
|
+ msg)
|
|
|
+ conn.group_reply(env, {'result': [0, {}]})
|
|
|
+
|
|
|
+ (msg, env) = conn.group_recvmsg(nonblock=False)
|
|
|
+ self.assertEqual('module_spec', msg['command'][0])
|
|
|
+ conn.group_reply(env, {'result': [0]})
|
|
|
+
|
|
|
+ (msg, env) = conn.group_recvmsg(nonblock=False)
|
|
|
+ self.assertEqual({'command': ['get_config',
|
|
|
+ {'module_name': 'Msgq'}]},
|
|
|
+ msg)
|
|
|
+ conn.group_reply(env, {'result': [0, {}]})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ synchronised = False
|
|
|
+ attempts = 100
|
|
|
+ while not synchronised:
|
|
|
+ time.sleep(0.1)
|
|
|
+ seq = conn.group_sendmsg({'command': ['Are you running?']},
|
|
|
+ 'Msgq', want_answer=True)
|
|
|
+ msg = conn.group_recvmsg(nonblock=False, seq=seq)
|
|
|
+ synchronised = msg[0] != -1
|
|
|
+ self.assertTrue(synchronised)
|
|
|
+
|
|
|
+ conn.group_subscribe("notifications/cc_members")
|
|
|
+ (msg, env) = conn.group_recvmsg(nonblock=False)
|
|
|
+ self.assertEqual({'notification': ['subscribed', {
|
|
|
+ 'client': conn.lname,
|
|
|
+ 'group': 'notifications/cc_members'
|
|
|
+ }]}, msg)
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
isc.log.init("msgq-tests")
|
|
|
isc.log.resetUnitTestRootLogger()
|