Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Linting code
Browse files Browse the repository at this point in the history
  • Loading branch information
Grokzen committed Apr 3, 2016
1 parent 88a86d3 commit c383080
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
4 changes: 3 additions & 1 deletion rediscluster/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def make_connection(self, node):
"""
if self.count_all_num_connections(node) >= self.max_connections:
if self.max_connections_per_node:
raise RedisClusterException("Too many connection ({}) for node: {}".format(self.count_all_num_connections(node), node['name']))
raise RedisClusterException("Too many connection ({0}) for node: {1}".format(self.count_all_num_connections(node), node['name']))

raise RedisClusterException("Too many connections")

Expand Down Expand Up @@ -197,6 +197,8 @@ def disconnect(self):
connection.disconnect()

def count_all_num_connections(self, node):
"""
"""
if self.max_connections_per_node:
return self._created_connections_per_node.get(node['name'], 0)

Expand Down
82 changes: 39 additions & 43 deletions tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,46 +440,42 @@ def test_channel_subscribe(self, r):
p.subscribe('foo')


class TestPubSubThreadedPublish(object):

def test_pubsub_thread_publish(self):
"""
This test will never fail but it will still show and be viable to use
and to test the threading capability of the connectionpool and the publish
mechanism.
"""
startup_nodes = [{"host": "127.0.0.1", "port": "7000"}]

r = StrictRedisCluster(
startup_nodes=startup_nodes,
decode_responses=True,
max_connections=16,
max_connections_per_node=16,
)

p = r.pubsub()

def t_run(rc, pub):
for i in range(0, 50):
rc.publish('foo', 'bar')
rc.publish('bar', 'foo')
rc.publish('asd', 'dsa')
rc.publish('dsa', 'asd')
rc.publish('qwe', 'bar')
rc.publish('ewq', 'foo')
rc.publish('wer', 'dsa')
rc.publish('rew', 'asd')

# Use this for debugging
# print(rc.connection_pool._available_connections)
# print(rc.connection_pool._in_use_connections)
# print(rc.connection_pool._created_connections)

try:
threads = []
for i in range(10):
t = threading.Thread(target=t_run, args=(r, p))
threads.append(t)
t.start()
except:
print("Error: unable to start thread")
def test_pubsub_thread_publish():
"""
This test will never fail but it will still show and be viable to use
and to test the threading capability of the connectionpool and the publish
mechanism.
"""
startup_nodes = [{"host": "127.0.0.1", "port": "7000"}]

r = StrictRedisCluster(
startup_nodes=startup_nodes,
decode_responses=True,
max_connections=16,
max_connections_per_node=16,
)

def t_run(rc):
for i in range(0, 50):
rc.publish('foo', 'bar')
rc.publish('bar', 'foo')
rc.publish('asd', 'dsa')
rc.publish('dsa', 'asd')
rc.publish('qwe', 'bar')
rc.publish('ewq', 'foo')
rc.publish('wer', 'dsa')
rc.publish('rew', 'asd')

# Use this for debugging
# print(rc.connection_pool._available_connections)
# print(rc.connection_pool._in_use_connections)
# print(rc.connection_pool._created_connections)

try:
threads = []
for i in range(10):
t = threading.Thread(target=t_run, args=(r,))
threads.append(t)
t.start()
except Exception:
print("Error: unable to start thread")

0 comments on commit c383080

Please sign in to comment.