|
10 | 10 | import warnings |
11 | 11 |
|
12 | 12 | import tarantool |
| 13 | +from tarantool.connection_pool import Status |
13 | 14 | from tarantool.error import ( |
14 | 15 | ClusterConnectWarning, |
15 | 16 | DatabaseError, |
@@ -581,6 +582,52 @@ def test_16_is_closed(self): |
581 | 582 |
|
582 | 583 | self.assertEqual(self.pool.is_closed(), True) |
583 | 584 |
|
| 585 | + def test_17_instance_bootstrap_error_does_not_kill_refresh(self): |
| 586 | + warnings.simplefilter('ignore', category=PoolTolopogyWarning) |
| 587 | + |
| 588 | + self.set_cluster_ro([False, True, True, True, True]) |
| 589 | + |
| 590 | + self.pool = tarantool.ConnectionPool( |
| 591 | + addrs=self.addrs, |
| 592 | + user='test', |
| 593 | + password='test', |
| 594 | + refresh_delay=0.2) |
| 595 | + |
| 596 | + self.pool.ping(mode=tarantool.Mode.RW) |
| 597 | + |
| 598 | + unit = self.pool.pool[f"{self.addrs[0]['host']}:{self.addrs[0]['port']}"] |
| 599 | + |
| 600 | + # Simulate an instance which is up, but has not finished its |
| 601 | + # bootstrap yet: box.info fails with a plain DatabaseError |
| 602 | + # instead of a NetworkError. |
| 603 | + resp = self.servers[0].admin(r""" |
| 604 | + rawset(_G, 'box_info_backup', box.info) |
| 605 | + box.info = function() |
| 606 | + box.error({code = 116, |
| 607 | + reason = "Instance bootstrap hasn't finished yet"}) |
| 608 | + end |
| 609 | + return true |
| 610 | + """) |
| 611 | + assert_admin_success(resp) |
| 612 | + |
| 613 | + def expect_instance_unhealthy_and_refresh_alive(): |
| 614 | + self.assertTrue(unit.thread.is_alive(), |
| 615 | + 'refresh thread died on a DatabaseError') |
| 616 | + self.assertEqual(unit.state.status, Status.UNHEALTHY) |
| 617 | + |
| 618 | + self.retry(func=expect_instance_unhealthy_and_refresh_alive) |
| 619 | + |
| 620 | + resp = self.servers[0].admin(r""" |
| 621 | + box.info = box_info_backup |
| 622 | + return true |
| 623 | + """) |
| 624 | + assert_admin_success(resp) |
| 625 | + |
| 626 | + def expect_rw_request_succeed(): |
| 627 | + self.pool.ping(mode=tarantool.Mode.RW) |
| 628 | + |
| 629 | + self.retry(func=expect_rw_request_succeed) |
| 630 | + |
584 | 631 | def tearDown(self): |
585 | 632 | if self.pool: |
586 | 633 | self.pool.close() |
|
0 commit comments