Commit eaefef0e authored by Michal Vaner's avatar Michal Vaner
Browse files

Introduce WouldBlockForever test exception

It is thrown if a blocking read is requested on empty fake_session.
Fixed tests that depended on wrong fake_session behaviour/sideeffected
on it.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac349@3111 e5f2f494-b856-4b98-b285-d166d9295462
parent 0549f65b
'\" t
.\" Title: bind10
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Generator: DocBook XSL Stylesheets v1.76.0 <http://docbook.sf.net/>
.\" Date: July 29, 2010
.\" Manual: BIND10
.\" Source: BIND10
......@@ -9,6 +9,15 @@
.\"
.TH "BIND10" "8" "July 29, 2010" "BIND10" "BIND10"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
......
......@@ -125,6 +125,8 @@ class TestModuleCCSession(unittest.TestCase):
self.assertTrue("Spec1" in fake_session.subscriptions)
self.assertEqual(len(fake_session.message_queue), 0)
fake_session.group_sendmsg(None, 'Spec1')
fake_session.group_sendmsg(None, 'Spec1')
self.assertRaises(ModuleCCSessionError, mccs.start)
self.assertEqual(len(fake_session.message_queue), 2)
self.assertEqual({'command': ['module_spec', {'module_name': 'Spec1'}]},
......@@ -150,6 +152,8 @@ class TestModuleCCSession(unittest.TestCase):
fake_session = FakeModuleCCSession()
mccs = self.create_session("spec2.spec", None, None, fake_session)
self.assertEqual(len(fake_session.message_queue), 0)
fake_session.group_sendmsg(None, 'Spec2')
fake_session.group_sendmsg(None, 'Spec2')
self.assertRaises(ModuleCCSessionError, mccs.start)
self.assertEqual(len(fake_session.message_queue), 2)
self.assertEqual({'command': ['module_spec', mccs.specification._module_spec]},
......@@ -173,6 +177,8 @@ class TestModuleCCSession(unittest.TestCase):
mccs = self.create_session("spec2.spec", None, None, fake_session)
mccs.set_config_handler(self.my_config_handler_ok)
self.assertEqual(len(fake_session.message_queue), 0)
fake_session.group_sendmsg(None, 'Spec2')
fake_session.group_sendmsg(None, 'Spec2')
self.assertRaises(ModuleCCSessionError, mccs.start)
self.assertEqual(len(fake_session.message_queue), 2)
self.assertEqual({'command': ['module_spec', mccs.specification._module_spec]},
......@@ -196,6 +202,8 @@ class TestModuleCCSession(unittest.TestCase):
mccs = self.create_session("spec2.spec", None, None, fake_session)
mccs.set_config_handler(self.my_config_handler_ok)
self.assertEqual(len(fake_session.message_queue), 0)
fake_session.group_sendmsg(None, 'Spec2')
fake_session.group_sendmsg(None, 'Spec2')
self.assertRaises(ModuleCCSessionError, mccs.start)
self.assertEqual(len(fake_session.message_queue), 2)
self.assertEqual({'command': ['module_spec', mccs.specification._module_spec]},
......@@ -382,6 +390,7 @@ class TestModuleCCSession(unittest.TestCase):
self.assertRaises(ModuleCCSessionError, mccs.get_remote_config_value, "Spec2", "item1")
self.assertFalse("Spec2" in fake_session.subscriptions)
fake_session.group_sendmsg(None, 'Spec2')
rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
self.assertTrue("Spec2" in fake_session.subscriptions)
self.assertEqual("Spec2", rmodname)
......@@ -395,6 +404,7 @@ class TestModuleCCSession(unittest.TestCase):
self.assertRaises(ModuleCCSessionError, mccs.get_remote_config_value, "Spec2", "item1")
# test if unsubscription is alse sent when object is deleted
fake_session.group_sendmsg({'result' : [0]}, 'Spec2')
rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
self.assertTrue("Spec2" in fake_session.subscriptions)
mccs = None
......@@ -405,6 +415,7 @@ class TestModuleCCSession(unittest.TestCase):
fake_session = FakeModuleCCSession()
mccs = self.create_session("spec1.spec", None, None, fake_session)
mccs.set_command_handler(self.my_command_handler_ok)
fake_session.group_sendmsg(None, 'Spec2')
rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
# remove the 'get config' from the queue
......
......@@ -255,6 +255,7 @@ class TestConfigManager(unittest.TestCase):
self.fake_session.get_message(self.name, None))
self.assertEqual(len(self.fake_session.message_queue), 0)
self.fake_session.group_sendmsg(None, 'ConfigManager')
self._handle_msg_helper({ "command": [ "set_config", [ ] ] },
{'result': [1, 'Wrong number of arguments']} )
self._handle_msg_helper({ "command": [ "set_config", [ self.name, { "test": 125 }] ] },
......
......@@ -17,6 +17,13 @@
import isc
class WouldBlockForever(Exception):
"""
This is thrown by the FakeModuleCCSession if it would need
to block forever for incoming message.
"""
pass
#
# We can probably use a more general version of this
#
......@@ -64,13 +71,18 @@ class FakeModuleCCSession:
if 'group' in env:
self.message_queue.append([ env['group'], None, msg])
def group_recvmsg(self, blocking, seq = None):
def group_recvmsg(self, nonblock=True, seq = None):
for qm in self.message_queue:
if qm[0] in self.subscriptions and (qm[1] == None or qm[1] in self.subscriptions[qm[0]]):
if qm[0] in self.subscriptions and (qm[1] == None or qm[1] in
self.subscriptions[qm[0]]):
self.message_queue.remove(qm)
return qm[2], {'group': qm[0], 'from': qm[1]}
if self._timeout == 0:
return None, None
if nonblock:
return None, None
else:
raise WouldBlockForever(
"Blocking read without timeout and no message ready")
else:
raise isc.cc.SessionTimeout("Timeout set but no data to "
"return to group_recvmsg()")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment