Parcourir la source

[1427] The drop_application method

Michal 'vorner' Vaner il y a 13 ans
Parent
commit
34de4dab53

+ 12 - 1
src/lib/python/isc/bind10/socket_cache.py

@@ -263,4 +263,15 @@ class Cache:
         If the application is invalid (no get_socket was successful with this
         value of application), it raises ValueError.
         """
-        pass
+        try:
+            # Get a copy. Who knows how iteration works through sets if we
+            # delete from it during the time, so we'll just have our own copy
+            # to iterate
+            to_drop = set(self._active_apps[application])
+        except KeyError:
+            raise ValueError("Application " + str(application) +
+                             " doesn't hold any sockets")
+        for token in to_drop:
+            self.drop_socket(token)
+        # We don't call del now. The last drop_socket should have
+        # removed the application key as well.

+ 23 - 0
src/lib/python/isc/bind10/tests/socket_cache_test.py

@@ -280,6 +280,29 @@ class SocketCacheTest(Test):
         # Trying to get it again fails
         self.assertRaises(ValueError, self.__cache.get_socket, token, app)
 
+    def test_drop_application(self):
+        """
+        Test that a drop_application calls drop_socket on all the sockets
+        held by the application.
+        """
+        sockets = set()
+        def drop_socket(token):
+            sockets.add(token)
+        # Mock the drop_socket so we know it is called
+        self.__cache.drop_socket = drop_socket
+        self.assertRaises(ValueError, self.__cache.drop_application,
+                          "bad token")
+        self.assertEqual(set(), sockets)
+        # Put the tokens into active_apps. Nothing else should be touched
+        # by this call, so leave it alone.
+        self.__cache._active_apps = {
+            1: set(['t1', 't2']),
+            2: set(['t3'])
+        }
+        self.__cache.drop_application(1)
+        self.assertEqual({2: set(['t3'])}, self.__cache._active_apps)
+        self.assertEqual(set(['t1', 't2']), sockets)
+
 if __name__ == '__main__':
     isc.log.init("bind10")
     isc.log.resetUnitTestRootLogger()