Skip to content
Snippets Groups Projects
Commit 9a39c720 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

add more tests to CPManager

parent fa425c3f
No related branches found
No related tags found
No related merge requests found
# v2.21.4
* moar tests for CPManager
\ No newline at end of file
__version__ = '2.21.4a1'
__version__ = '2.21.4a2'
......@@ -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:
......
......@@ -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())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment