Andriy Kornatskyy avatar Andriy Kornatskyy committed 474802c

If an error has occurred during LazyPool aquire then get back item to pool and re-raise error.

Comments (0)

Files changed (2)

src/wheezy/core/pooling.py

         """ Return an item from pool. Blocks until an item
             is available.
         """
-        return self.create_factory(self.__items.get())
+        item = self.__items.get()
+        try:
+            return self.create_factory(item)
+        except:
+            self.get_back(item)
+            raise
 
     @property
     def count(self):

src/wheezy/core/tests/test_pooling.py

         assert pool.size == 10
         assert pool.count == 9
 
+    def test_acquire_error(self):
+        """ If an error has occurred during acquire then get back
+            an item to pool and re-raise error.
+        """
+        from wheezy.core.pooling import LazyPool
+        mock_create_factory = Mock(side_effect=Exception())
+        pool = LazyPool(mock_create_factory, 2)
+
+        self.assertRaises(Exception, pool.acquire)
+        assert pool.size == 2
+        assert pool.count == 2
+
     def test_get_back(self):
         """ An item is returned back to pool.
         """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.