From 9a39c7200bda41710df6d9dcf69b5af37b5dd41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 12 Aug 2022 00:48:14 +0200 Subject: [PATCH] add more tests to CPManager --- CHANGELOG.md | 1 + satella/__init__.py | 2 +- satella/coding/resources/cp_manager.py | 2 +- tests/test_coding/test_resources.py | 12 +++++++++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09878285..cdc9ff3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ # v2.21.4 +* moar tests for CPManager \ No newline at end of file diff --git a/satella/__init__.py b/satella/__init__.py index 1e35c5c5..68faeb8b 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.21.4a1' +__version__ = '2.21.4a2' diff --git a/satella/coding/resources/cp_manager.py b/satella/coding/resources/cp_manager.py index ab4c48f4..600f59bc 100644 --- a/satella/coding/resources/cp_manager.py +++ b/satella/coding/resources/cp_manager.py @@ -98,7 +98,7 @@ class CPManager(Monitor, Closeable, tp.Generic[T], metaclass=abc.ABCMeta): :param connection: connection to release """ obj_id = id(connection) - if self.id_to_times[obj_id] == self.max_cycle_no: + if self.id_to_times[obj_id] >= self.max_cycle_no: self._kill_connection(connection) else: try: diff --git a/tests/test_coding/test_resources.py b/tests/test_coding/test_resources.py index d819b2c1..c10c67da 100644 --- a/tests/test_coding/test_resources.py +++ b/tests/test_coding/test_resources.py @@ -28,6 +28,8 @@ class TestResources(unittest.TestCase): if self.i == 3: self.value_error_emitted = True raise ValueError() + elif self.i > 3: + raise RuntimeError('called too often') def close(self): self.closed = True @@ -48,9 +50,6 @@ class TestResources(unittest.TestCase): self.already_acquired.add(v.id) return v - def fail_connection(self, connection) -> None: - super().fail_connection(connection) - def release_connection(self, connection) -> None: print(f'Releasing connection {connection.id}') self.already_acquired.remove(connection.id) @@ -81,6 +80,13 @@ class TestResources(unittest.TestCase): cp.release_connection(conns.pop()) ret.result(timeout=20) ret2.result(timeout=20) + for i in range(20): + conn = cp.acquire_connection() + try: + conn.do() + except ValueError: + cp.fail_connection(conn) + cp.release_connection(conn) while conns: cp.release_connection(conns.pop()) -- GitLab