Skip to content

Commit b94e92a

Browse files
MirochillMockird31
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 5dda1b3 commit b94e92a

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
@@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
queued requests (PR #336).
1717
- Recover `ConnectionPool` instances after a cluster restart
1818
(PR #343).
19+
- Fix typo in the name: PoolTolopogy -> PoolTopology. Ensured
20+
backward compatibility using aliases (PR #345).
1921

2022
## 1.2.0 - 2024-03-27
2123

‎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
DatabaseError,
2929
NetworkError,
@@ -295,14 +295,14 @@ def _getnext_by_mode(self, *iters, err_msg="Can't find healthy instance in pool"
295295
296296
:rtype: :class:`~tarantool.connection_pool.PoolUnit`
297297
298-
:raise: :exc:`~tarantool.error.PoolTolopogyError`
298+
:raise: :exc:`~tarantool.error.PoolTopologyError`
299299
300300
:meta private:
301301
"""
302302
for itr in iters:
303303
if itr is not None:
304304
return next(itr)
305-
raise PoolTolopogyError(err_msg)
305+
raise PoolTopologyError(err_msg)
306306

307307
def getnext(self, mode):
308308
"""
@@ -313,7 +313,7 @@ def getnext(self, mode):
313313
314314
:rtype: :class:`~tarantool.connection_pool.PoolUnit`
315315
316-
:raise: :exc:`~tarantool.error.PoolTolopogyError`
316+
:raise: :exc:`~tarantool.error.PoolTopologyError`
317317
"""
318318

319319
if self.rebuild_needed:
@@ -579,28 +579,28 @@ def _get_new_state(self, unit):
579579
except DatabaseError as exc:
580580
msg = (f"Failed to get box.info for {unit.get_address()}, "
581581
f"reason: {repr(exc)}")
582-
warn(msg, PoolTolopogyWarning)
582+
warn(msg, PoolTopologyWarning)
583583
return InstanceState(Status.UNHEALTHY)
584584

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

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

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

606606
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
@@ -15,6 +15,8 @@
1515
ClusterConnectWarning,
1616
DatabaseError,
1717
NetworkWarning,
18+
PoolTopologyError,
19+
PoolTopologyWarning,
1820
PoolTolopogyError,
1921
PoolTolopogyWarning,
2022
)
@@ -24,6 +26,12 @@
2426
from .utils import assert_admin_success
2527

2628

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

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

195203
self.retry(func=expect_rw_to_fail_if_there_are_no_rw)
@@ -209,7 +217,7 @@ def expect_prefer_rw_iterate_through_all_instances_if_there_are_no_rw():
209217

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

215223
self.retry(func=expect_ro_to_fail_if_there_are_no_ro)
@@ -515,7 +523,7 @@ def test_12_execute(self):
515523

516524
def test_13_failover(self):
517525
warnings.simplefilter('ignore', category=NetworkWarning)
518-
warnings.simplefilter('ignore', category=PoolTolopogyWarning)
526+
warnings.simplefilter('ignore', category=PoolTopologyWarning)
519527

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

0 commit comments

Comments
 (0)