Browse Source

[1429] The socket_consumer_dead method

Michal 'vorner' Vaner 13 years ago
parent
commit
b092df6f17
2 changed files with 43 additions and 1 deletions
  1. 1 1
      src/bin/bind10/bind10_src.py.in
  2. 42 0
      src/bin/bind10/tests/bind10_test.py.in

+ 1 - 1
src/bin/bind10/bind10_src.py.in

@@ -828,7 +828,7 @@ class BoB:
         sockets sent to it are to be considered closed. This function signals
         so to the _socket_cache.
         """
-        pass
+        self._socket_cache.drop_application(unix_socket.fileno())
 
     def insert_creator(self, creator):
         """

+ 42 - 0
src/bin/bind10/tests/bind10_test.py.in

@@ -98,6 +98,48 @@ class TestProcessInfo(unittest.TestCase):
         self.assertTrue(type(pi.pid) is int)
         self.assertNotEqual(pi.pid, old_pid)
 
+class TestCacheCommands(unittest.TestCase):
+    """
+    Test methods of boss related to the socket cache and socket handling.
+    """
+    def setUp(self):
+        """
+        Prepare the boss for some tests.
+
+        Also prepare some variables we need.
+        """
+        self.__boss = BoB()
+        # Fake the cache here so we can pretend it is us and hijack the
+        # calls to its methods.
+        self.__boss._socket_cache = self
+        # What was and wasn't called.
+        self.__drop_app_called = None
+
+    class FalseSocket:
+        """
+        A socket where we can fake methods we need instead of having a real
+        socket.
+        """
+        def fileno(self):
+            """
+            The file number. Used for identifying the remote application.
+            """
+            return 42
+
+    def drop_application(self, application):
+        """
+        Part of pretending to be the cache. Logs the parameter to
+        self.__drop_app_called.
+        """
+        self.__drop_app_called = application
+
+    def test_consumer_dead(self):
+        """
+        Test that it calls the drop_application method of the cache.
+        """
+        self.__boss.socket_consumer_dead(self.FalseSocket())
+        self.assertEqual(42, self.__drop_app_called)
+
 class TestBoB(unittest.TestCase):
     def test_init(self):
         bob = BoB()