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 8, 2016
1 parent 6a2f01e commit 54e1bed
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
6 changes: 3 additions & 3 deletions rediscluster/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,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 All @@ -181,15 +181,15 @@ def release(self, connection):
# Remove the current connection from _in_use_connection and add it back to the available pool
# There is cases where the connection is to be removed but it will not exist and there
# must be a safe way to remove
i_c = self._in_use_connections.get(connection._node["name"], set())
i_c = self._in_use_connections.get(connection.node["name"], set())

if connection in i_c:
i_c.remove(connection)
else:
pass
# TODO: Log.warning("Tried to release connection that did not exist any longer : {0}".format(connection))

self._available_connections.setdefault(connection._node["name"], []).append(connection)
self._available_connections.setdefault(connection.node["name"], []).append(connection)

def disconnect(self):
"""
Expand Down
82 changes: 39 additions & 43 deletions tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,46 +435,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 54e1bed

Please sign in to comment.