Skip to content

Commit 618dab4

Browse files
Mirochillr.inyakin
authored andcommitted
pool: fix pool topology error names
Fixed a typo in the name: PoolTolopogy to PoolTopology. Ensured backward compatibility by adding aliases. Closes #332
1 parent 1719e9c commit 618dab4

4 files changed

Lines changed: 29 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Set upper bound for version of setuptools (PR #342).
1515
- Reduce idle CPU usage in `ConnectionPool` while waiting for
1616
queued requests (PR #336).
17+
- Fix typo in the name: PoolTolopogy -> PoolTopology. Ensured
18+
backward compatibility using aliases (PR #345).
1719

1820
## 1.2.0 - 2024-03-27
1921

tarantool/connection_pool.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
)
2323
from tarantool.error import (
2424
ClusterConnectWarning,
25-
PoolTolopogyError,
26-
PoolTolopogyWarning,
25+
PoolTopologyError,
26+
PoolTopologyWarning,
2727
ConfigurationError,
2828
NetworkError,
2929
warn
@@ -294,14 +294,14 @@ def _getnext_by_mode(self, *iters, err_msg="Can't find healthy instance in pool"
294294
295295
:rtype: :class:`~tarantool.connection_pool.PoolUnit`
296296
297-
:raise: :exc:`~tarantool.error.PoolTolopogyError`
297+
:raise: :exc:`~tarantool.error.PoolTopologyError`
298298
299299
:meta private:
300300
"""
301301
for itr in iters:
302302
if itr is not None:
303303
return next(itr)
304-
raise PoolTolopogyError(err_msg)
304+
raise PoolTopologyError(err_msg)
305305

306306
def getnext(self, mode):
307307
"""
@@ -312,7 +312,7 @@ def getnext(self, mode):
312312
313313
:rtype: :class:`~tarantool.connection_pool.PoolUnit`
314314
315-
:raise: :exc:`~tarantool.error.PoolTolopogyError`
315+
:raise: :exc:`~tarantool.error.PoolTopologyError`
316316
"""
317317

318318
if self.rebuild_needed:
@@ -578,28 +578,28 @@ def _get_new_state(self, unit):
578578
except NetworkError as exc:
579579
msg = (f"Failed to get box.info for {unit.get_address()}, "
580580
f"reason: {repr(exc)}")
581-
warn(msg, PoolTolopogyWarning)
581+
warn(msg, PoolTopologyWarning)
582582
return InstanceState(Status.UNHEALTHY)
583583

584584
try:
585585
read_only = resp.data[0]['ro']
586586
except (IndexError, KeyError) as exc:
587587
msg = (f"Incorrect box.info response from {unit.get_address()}"
588588
f"reason: {repr(exc)}")
589-
warn(msg, PoolTolopogyWarning)
589+
warn(msg, PoolTopologyWarning)
590590
return InstanceState(Status.UNHEALTHY)
591591

592592
try:
593593
status = resp.data[0]['status']
594594

595595
if status != 'running':
596596
msg = f"{unit.get_address()} instance status is not 'running'"
597-
warn(msg, PoolTolopogyWarning)
597+
warn(msg, PoolTopologyWarning)
598598
return InstanceState(Status.UNHEALTHY)
599599
except (IndexError, KeyError) as exc:
600600
msg = (f"Incorrect box.info response from {unit.get_address()}"
601601
f"reason: {repr(exc)}")
602-
warn(msg, PoolTolopogyWarning)
602+
warn(msg, PoolTopologyWarning)
603603
return InstanceState(Status.UNHEALTHY)
604604

605605
return InstanceState(Status.HEALTHY, read_only)

tarantool/error.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,14 @@ class ClusterConnectWarning(UserWarning):
309309
"""
310310

311311

312-
class PoolTolopogyWarning(UserWarning):
312+
class PoolTopologyWarning(UserWarning):
313313
"""
314314
Warning related to unsatisfying `box.info.ro`_ state of
315315
pool instances.
316316
"""
317317

318318

319-
class PoolTolopogyError(DatabaseError):
319+
class PoolTopologyError(DatabaseError):
320320
"""
321321
Exception raised due to unsatisfying `box.info.ro`_ state of
322322
pool instances.
@@ -325,6 +325,11 @@ class PoolTolopogyError(DatabaseError):
325325
"""
326326

327327

328+
# Backward-compatible aliases for the previously exposed misspelled names.
329+
PoolTolopogyWarning = PoolTopologyWarning
330+
PoolTolopogyError = PoolTopologyError
331+
332+
328333
class CrudModuleError(DatabaseError):
329334
"""
330335
Exception raised for errors that are related to

test/suites/test_pool.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
ClusterConnectWarning,
1515
DatabaseError,
1616
NetworkWarning,
17+
PoolTopologyError,
18+
PoolTopologyWarning,
1719
PoolTolopogyError,
1820
PoolTolopogyWarning,
1921
)
@@ -23,6 +25,12 @@
2325
from .utils import assert_admin_success
2426

2527

28+
class TestSuitePoolErrorAliases(unittest.TestCase): # pylint: disable=too-few-public-methods
29+
def test_pool_topology_error_aliases(self):
30+
self.assertIs(PoolTolopogyError, PoolTopologyError)
31+
self.assertIs(PoolTolopogyWarning, PoolTopologyWarning)
32+
33+
2634
def create_server(_id):
2735
srv = TarantoolServer()
2836
srv.script = 'test/suites/box.lua'
@@ -188,7 +196,7 @@ def get_port(self, mode):
188196

189197
# Expect RW to fail if there are no RW.
190198
def expect_rw_to_fail_if_there_are_no_rw():
191-
with self.assertRaises(PoolTolopogyError):
199+
with self.assertRaises(PoolTopologyError):
192200
self.pool.eval('return box.cfg.listen', mode=tarantool.Mode.RW)
193201

194202
self.retry(func=expect_rw_to_fail_if_there_are_no_rw)
@@ -208,7 +216,7 @@ def expect_prefer_rw_iterate_through_all_instances_if_there_are_no_rw():
208216

209217
# Expect RO to fail if there are no RO.
210218
def expect_ro_to_fail_if_there_are_no_ro():
211-
with self.assertRaises(PoolTolopogyError):
219+
with self.assertRaises(PoolTopologyError):
212220
self.pool.eval('return box.cfg.listen', mode=tarantool.Mode.RO)
213221

214222
self.retry(func=expect_ro_to_fail_if_there_are_no_ro)
@@ -514,7 +522,7 @@ def test_12_execute(self):
514522

515523
def test_13_failover(self):
516524
warnings.simplefilter('ignore', category=NetworkWarning)
517-
warnings.simplefilter('ignore', category=PoolTolopogyWarning)
525+
warnings.simplefilter('ignore', category=PoolTopologyWarning)
518526

519527
self.set_cluster_ro([False, True, True, True, True])
520528
self.pool = tarantool.ConnectionPool(

0 commit comments

Comments
 (0)