6
class ConnectionPoolTestCase(unittest.TestCase):
7
def test_multiple_connections(self):
8
# 2 clients to the same host/port/db/pool should use the same connection
9
pool = redis.ConnectionPool()
10
r1 = redis.Redis(host='localhost', port=6379, db=9, connection_pool=pool)
11
r2 = redis.Redis(host='localhost', port=6379, db=9, connection_pool=pool)
12
self.assertEquals(r1.connection, r2.connection)
14
# if one of them switches, they should have
15
# separate conncetion objects
16
r2.select(db=10, host='localhost', port=6379)
17
self.assertNotEqual(r1.connection, r2.connection)
19
conns = [r1.connection, r2.connection]
22
# but returning to the original state shares the object again
23
r2.select(db=9, host='localhost', port=6379)
24
self.assertEquals(r1.connection, r2.connection)
26
# the connection manager should still have just 2 connections
27
mgr_conns = pool.get_all_connections()
29
self.assertEquals(conns, mgr_conns)
31
def test_threaded_workers(self):
32
r = redis.Redis(host='localhost', port=6379, db=9)
46
t1 = threading.Thread(target=_info_worker)
47
t2 = threading.Thread(target=_keys_worker)