Browse Source

Merge branch 'trac698'

Conflicts:
	ChangeLog
Naoki Kambe 14 years ago
parent
commit
0355bddc92

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+  212.  [bug]		naokikambe
+	Fixed that the ModuleCCSession object may group_unsubscribe in the
+	closed CC session in being deleted.
+	(Trac #698, git tbdtbdtbdtbdtbdtbdtbdtbdtbdtbdtbdtbdttbd)
+
   211.  [func]		shane
 	Implement "--brittle" option, which causes the server to exit
         if any of BIND 10's processes dies.

+ 3 - 0
src/lib/python/isc/config/ccsession.py

@@ -151,6 +151,9 @@ class ModuleCCSession(ConfigData):
         self._remote_module_configs = {}
 
     def __del__(self):
+        # If the CC Session obejct has been closed, it returns
+        # immediately.
+        if self._session._closed: return
         self._session.group_unsubscribe(self._module_name, "*")
         for module_name in self._remote_module_configs:
             self._session.group_unsubscribe(module_name)

+ 12 - 1
src/lib/python/isc/config/tests/ccsession_test.py

@@ -234,7 +234,18 @@ class TestModuleCCSession(unittest.TestCase):
         fake_session = FakeModuleCCSession()
         mccs = self.create_session("spec1.spec", None, None, fake_session)
         mccs.close()
-        self.assertEqual("closed", fake_session._socket)
+        self.assertEqual(None, fake_session._socket)
+
+    def test_del_opened(self):
+        fake_session = FakeModuleCCSession()
+        mccs = self.create_session("spec1.spec", None, None, fake_session)
+        mccs.__del__() # with opened fake_session
+
+    def test_del_closed(self):
+        fake_session = FakeModuleCCSession()
+        mccs = self.create_session("spec1.spec", None, None, fake_session)
+        fake_session.close()
+        mccs.__del__() # with closed fake_session
 
     def my_config_handler_ok(self, new_config):
         return isc.config.ccsession.create_answer(0)

+ 8 - 1
src/lib/python/isc/config/tests/unittest_fakesession.py

@@ -35,6 +35,7 @@ class FakeModuleCCSession:
         # the message_queue is empty when receive is called, throw
         # a SessionTimeout
         self._timeout = 0
+        self._closed = False
 
     def group_subscribe(self, group_name, instance_name = None):
         if not group_name in self.subscriptions:
@@ -43,6 +44,11 @@ class FakeModuleCCSession:
             self.subscriptions[group_name].append(instance_name)
             
     def group_unsubscribe(self, group_name, instance_name = None):
+
+        # raises SessionError if the session has been already closed.
+        if self._closed:
+            raise isc.cc.SessionError("Session has been closed.")        
+
         if group_name in self.subscriptions:
             if instance_name:
                 if len(self.subscriptions[group_name]) > 1:
@@ -94,7 +100,8 @@ class FakeModuleCCSession:
 
     def close(self):
         # need to pass along somehow that this function has been called,
-        self._socket = "closed"
+        self._socket = None
+        self._closed = True
 
     def set_timeout(self, timeout):
         self._timeout = timeout