BIND 10 trac1914, updated. 86a88ca3f958089b8d586d77f0e501f2792320d3 [1924] (minor) Docstrings for the tests
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jan 28 15:25:25 UTC 2013
The branch, trac1914 has been updated
via 86a88ca3f958089b8d586d77f0e501f2792320d3 (commit)
via 85b7b8462a2bab6084aa724a9fe85208d2c80f84 (commit)
via 6d9b521367bc30b39209551ccbea6c8e20e140d8 (commit)
from 079a6684785bb75f1ae2c2c2ebfc1838831e783d (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 86a88ca3f958089b8d586d77f0e501f2792320d3
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Jan 28 16:23:16 2013 +0100
[1924] (minor) Docstrings for the tests
commit 85b7b8462a2bab6084aa724a9fe85208d2c80f84
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Jan 28 16:20:09 2013 +0100
[1924] Decode the delivered messages in test
Decode the messages to see they are not errors. Check they contain
correct data and they are delivered to the correct socket.
Parsing of the errors is not present yet, it needs to be found out how
such an error looks like.
commit 6d9b521367bc30b39209551ccbea6c8e20e140d8
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Jan 28 15:54:40 2013 +0100
[1924] Skeleton of the test for delivery errors
Let the msgq send several messages, some of them are deliverable, some
of them not. Some require reporting of error, some don't. Check it
generates the errors in the right moments and delivers the messages that
can be.
The test is not complete yet, we don't have parsing of the messages.
-----------------------------------------------------------------------
Summary of changes:
src/bin/msgq/tests/msgq_test.py | 90 +++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/bin/msgq/tests/msgq_test.py b/src/bin/msgq/tests/msgq_test.py
index 88bb022..c5e0551 100644
--- a/src/bin/msgq/tests/msgq_test.py
+++ b/src/bin/msgq/tests/msgq_test.py
@@ -11,6 +11,8 @@ import threading
import isc.cc
import collections
import isc.log
+import struct
+import json
#
# Currently only the subscription part and some sending is implemented...
@@ -140,6 +142,94 @@ class TestSubscriptionManager(unittest.TestCase):
self.sm.subscribe('ConfigManager', '*', 's3')
self.assertEqual(1, self.__cfgmgr_ready_called)
+class MsgQTest(unittest.TestCase):
+ """
+ Tests for the behaviour of MsgQ. This is for the core of MsgQ, other
+ subsystems are in separate test fixtures.
+ """
+ def setUp(self):
+ self.__msgq = MsgQ()
+
+ def parse_msg(self, msg):
+ """
+ Parse a binary representation of message to the routing header and the
+ data payload. It assumes the message is correctly encoded and the
+ payload is not omitted. It'd probably throw in other cases, but we
+ don't use it in such situations in this test.
+ """
+ (length, header_len) = struct.unpack('>IH', msg[:6])
+ header = json.loads(msg[6:6 + header_len].decode('utf-8'))
+ data = json.loads(msg[6 + header_len:].decode('utf-8'))
+ return (header, data)
+
+ def test_undeliverable_errors(self):
+ """
+ Send several packets through the MsgQ and check it generates
+ undeliverable notifications under the correct circumstances.
+ """
+ sent_messages = []
+ def fake_end_prepared_msg(socket, msg):
+ sent_messages.append((socket, msg))
+ self.__msgq.send_prepared_msg = fake_end_prepared_msg
+ # These would be real sockets in the MsgQ, but we pass them as
+ # parameters only, so we don't need them to be. We use simple
+ # integers to tell one from another.
+ sender = 1
+ recipient = 2
+ # The routing headers and data to test with.
+ routing = {
+ 'to': '*',
+ 'group': 'group',
+ 'instance': '*',
+ 'seq': 42
+ }
+ data = {
+ "data": "Just some data"
+ }
+ # Send the message. No recipient, but errors are not requested,
+ # so none is generated.
+ self.__msgq.process_command_send(sender, routing, data)
+ self.assertEqual([], sent_messages)
+ # Ask for errors if it can't be delivered.
+ routing["wants_reply"] = True
+ self.__msgq.process_command_send(sender, routing, data)
+ self.assertEqual(1, len(sent_messages))
+ # TODO: Parse the message and check it looks correct. It should contain
+ # the reply header too.
+ sent_messages = []
+ # If the message is a reply itself, we never generate the errors, even
+ # if they can't be delivered. This is partly because the answer reuses
+ # the old header (which would then inherit the wants_reply flag) and
+ # partly we want to avoid loops of errors that can't be delivered.
+ # If a reply can't be delivered, the sender can't do much anyway even
+ # if notified.
+ routing["reply"] = 3
+ self.__msgq.process_command_send(sender, routing, data)
+ self.assertEqual([], sent_messages)
+ # If there are recipients (but no "reply" header), the error should not
+ # be sent and the message should get delivered.
+ del routing["reply"]
+ self.__msgq.subs.find = lambda group, instance: [recipient]
+ self.__msgq.process_command_send(sender, routing, data)
+ self.assertEqual(1, len(sent_messages))
+ self.assertEqual(2, sent_messages[0][0]) # The recipient
+ self.assertEqual((routing, data), self.parse_msg(sent_messages[0][1]))
+ sent_messages = []
+ # When we send a direct message and the recipient is not there, we get
+ # the error too
+ routing["to"] = "lname"
+ self.__msgq.process_command_send(sender, routing, data)
+ self.assertEqual(1, len(sent_messages))
+ # TODO: Parse the errors
+ # But when the recipient is there, it is delivered and no error is
+ # generated.
+ self.__msgq.lnames["lname"] = recipient
+ self.__msgq.process_command_send(sender, routing, data)
+ self.assertEqual(1, len(sent_messages))
+ self.assertEqual(2, sent_messages[0][0]) # The recipient
+ self.assertEqual((routing, data), self.parse_msg(sent_messages[0][1]))
+ sent_messages = []
+
class DummySocket:
"""
Dummy socket class.
More information about the bind10-changes
mailing list