Skip to content

Commit

Permalink
Improve tests, fix iter update
Browse files Browse the repository at this point in the history
  • Loading branch information
DifferentialOrange committed Feb 21, 2022
1 parent 8a9eff4 commit c960ade
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
4 changes: 4 additions & 0 deletions tarantool/connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ def update(self, new_pool):

if len(RW_pool) > 0:
self.RW_iter = cycle(RW_pool)
else:
self.RW_iter = None

if len(RO_pool) > 0:
self.RO_iter = cycle(RO_pool)
else:
self.RO_iter = None

def getnext(self, mode):
if mode == Mode.RW:
Expand Down
33 changes: 13 additions & 20 deletions test/suites/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def test_01_roundrobin(self):
self.set_cluster_ro([False, False, True, False, True])
RW_ports = set([str(self.addrs[0]['port']), str(self.addrs[1]['port']), str(self.addrs[3]['port'])])
RO_ports = set([str(self.addrs[2]['port']), str(self.addrs[4]['port'])])
all_ports = set()
for addr in self.addrs:
all_ports.add(str(addr['port']))

conn = tarantool.ConnectionPool(addrs=self.addrs, user='test', password='test')

Expand Down Expand Up @@ -119,37 +122,27 @@ def test_01_roundrobin(self):

self.assertSetEqual(PREFER_RO_ports_result, RO_ports)

def test_02_roundrobin_all_ro(self):
# Expect PREFER_RW iterate through all instances if there are no RW.
self.set_cluster_ro([True, True, True, True, True])
all_ports = set()
for addr in self.addrs:
all_ports.add(str(addr['port']))

conn = tarantool.ConnectionPool(addrs=self.addrs, user='test', password='test')
conn.update_ro_info()

# Expect PREFER_RW iterate through all instances if there are no RW.
PREFER_RW_ports_result = set()
PREFER_RW_ports_result_all_ro = set()
for i in range(len(self.servers)):
resp = conn.eval('return box.cfg.listen', mode=tarantool.Mode.PREFER_RW)
PREFER_RW_ports_result.add(resp.data[0])
PREFER_RW_ports_result_all_ro.add(resp.data[0])

self.assertSetEqual(PREFER_RW_ports_result, all_ports)
self.assertSetEqual(PREFER_RW_ports_result_all_ro, all_ports)

def test_03_roundrobin_all_rw(self):
# Expect PREFER_RO iterate through all instances if there are no RO.
self.set_cluster_ro([False, False, False, False, False])
all_ports = set()
for addr in self.addrs:
all_ports.add(str(addr['port']))
conn.update_ro_info()

conn = tarantool.ConnectionPool(addrs=self.addrs, user='test', password='test')

# Expect PREFER_RO iterate through all instances if there are no RO.
PREFER_RO_ports_result = set()
PREFER_RO_ports_result_all_rw = set()
for i in range(len(self.servers)):
resp = conn.eval('return box.cfg.listen', mode=tarantool.Mode.PREFER_RO)
PREFER_RO_ports_result.add(resp.data[0])
PREFER_RO_ports_result_all_rw.add(resp.data[0])

self.assertSetEqual(PREFER_RO_ports_result, all_ports)
self.assertSetEqual(PREFER_RO_ports_result_all_rw, all_ports)

def tearDown(self):
for srv in self.servers:
Expand Down

0 comments on commit c960ade

Please sign in to comment.