diff options
| author | Andy McCurdy <andy@andymccurdy.com> | 2014-03-10 21:48:35 -0700 |
|---|---|---|
| committer | Andy McCurdy <andy@andymccurdy.com> | 2014-03-10 21:48:35 -0700 |
| commit | da842ef917afadb169fb3f19d36b5d83c5c4a831 (patch) | |
| tree | 72059f8e57a08e5506257375050256bb27da0ea6 | |
| parent | f4f89e9516a2922c4ef2d7448c6ef30d8133fc84 (diff) | |
| download | redis-py-da842ef917afadb169fb3f19d36b5d83c5c4a831.tar.gz | |
make sure hiredis parser raises connection errors
| -rw-r--r-- | redis/connection.py | 5 | ||||
| -rw-r--r-- | tests/test_commands.py | 7 | ||||
| -rw-r--r-- | tests/test_connection_pool.py | 19 |
3 files changed, 23 insertions, 8 deletions
diff --git a/redis/connection.py b/redis/connection.py index 3b1ab89..8a064b3 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -200,6 +200,11 @@ class HiredisParser(BaseParser): response = self._reader.gets() if isinstance(response, ResponseError): response = self.parse_error(response.args[0]) + # hiredis only knows about ResponseErrors. + # self.parse_error() might turn the exception into a ConnectionError + # which needs raising. + if isinstance(response, ConnectionError): + raise response return response if HIREDIS_AVAILABLE: diff --git a/tests/test_commands.py b/tests/test_commands.py index 7f37665..0878076 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -74,13 +74,6 @@ class TestRedisCommands(object): r['b'] = 'bar' assert r.dbsize() == 2 - def test_debug_object(self, r): - r['a'] = 'foo' - debug_info = r.debug_object('a') - assert len(debug_info) > 0 - assert 'refcount' in debug_info - assert debug_info['refcount'] == 1 - def test_echo(self, r): assert r.echo('foo bar') == b('foo bar') diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index 80deb64..d6c4728 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -7,6 +7,10 @@ import re from threading import Thread from redis._compat import Queue +from .conftest import skip_if_server_version_lt + +# won't need this after next version of pytest +from distutils.version import StrictVersion class DummyConnection(object): @@ -165,7 +169,7 @@ class TestConnection(object): An error in Connection.on_connect should disconnect from the server see for details: https://github.com/andymccurdy/redis-py/issues/368 """ - # this assumed the Redis server being tested against doesn't have + # this assumes the Redis server being tested against doesn't have # 9999 databases ;) bad_connection = redis.Redis(db=9999) # an error should be raised on connect @@ -174,3 +178,16 @@ class TestConnection(object): pool = bad_connection.connection_pool assert len(pool._available_connections) == 1 assert not pool._available_connections[0]._sock + + # NOTE: Increment this version # when the DEBUG ERROR patch releases + @skip_if_server_version_lt('2.8.7') + def test_busy_loading_disconnects_socket(self, r): + """ + If Redis raises a LOADING error, the connection should be + disconnected and a BusyLoadingError raised + """ + with pytest.raises(redis.BusyLoadingError): + r.execute_command('DEBUG', 'ERROR', 'LOADING fake message') + pool = r.connection_pool + assert len(pool._available_connections) == 1 + assert not pool._available_connections[0]._sock |
