diff --git a/sprockets/clients/dynamodb/__init__.py b/sprockets/clients/dynamodb/__init__.py index c53b607..c0cfcea 100644 --- a/sprockets/clients/dynamodb/__init__.py +++ b/sprockets/clients/dynamodb/__init__.py @@ -4,7 +4,7 @@ except ImportError as error: def DynamoDB(*args, **kwargs): raise error -version_info = (0, 2, 2) +version_info = (0, 2, 3) __version__ = '.'.join(str(v) for v in version_info) # Response constants diff --git a/sprockets/clients/dynamodb/connector.py b/sprockets/clients/dynamodb/connector.py index d3acf8b..b7aa998 100644 --- a/sprockets/clients/dynamodb/connector.py +++ b/sprockets/clients/dynamodb/connector.py @@ -10,13 +10,16 @@ from tornado_aws import exceptions as aws_exceptions from . import utils from . import exceptions -# Stub ConnectionError for Python 2.7 that doesn't support it +# Stub ConnectionError && ConnectionResetError for Python 2.7 try: ConnectionError except NameError: class ConnectionError(Exception): pass + class ConnectionResetError(Exception): + pass + LOGGER = logging.getLogger(__name__) @@ -134,8 +137,11 @@ class DynamoDB(object): future.set_exception(exceptions.NoCredentialsError(str(error))) except aws_exceptions.NoProfileError as error: future.set_exception(exceptions.NoProfileError(str(error))) - except (socket.gaierror, ConnectionError) as req_err: - future.set_exception(exceptions.RequestException(req_err)) + except (ConnectionError, + ConnectionResetError, + OSError, + socket.gaierror) as error: + future.set_exception(exceptions.RequestException(str(error))) except httpclient.HTTPError as err: if err.code == 599: future.set_exception(exceptions.TimeoutException()) diff --git a/tests/api_tests.py b/tests/api_tests.py index 1a90c8f..541d426 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -13,7 +13,7 @@ from tornado import testing from tornado_aws import exceptions as aws_exceptions from sprockets.clients import dynamodb -from sprockets.clients.dynamodb import connector, exceptions +from sprockets.clients.dynamodb import exceptions class AsyncTestCase(testing.AsyncTestCase): @@ -113,6 +113,13 @@ class AWSClientTests(AsyncTestCase): with self.assertRaises(exceptions.RequestException): yield self.client.create_table(self.generic_table_definition()) + @testing.gen_test + def test_oserror_raises_request_exception(self): + with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch: + fetch.side_effect = OSError + with self.assertRaises(exceptions.RequestException): + yield self.client.create_table(self.generic_table_definition()) + @unittest.skipIf(sys.version_info.major < 3, 'ConnectionError is Python3 only') @testing.gen_test @@ -122,6 +129,14 @@ class AWSClientTests(AsyncTestCase): with self.assertRaises(exceptions.RequestException): yield self.client.create_table(self.generic_table_definition()) + @unittest.skipIf(sys.version_info.major < 3, + 'ConnectionResetError is Python3 only') + @testing.gen_test + def test_connection_reset_error_request_exception(self): + with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch: + fetch.side_effect = ConnectionResetError + with self.assertRaises(exceptions.RequestException): + yield self.client.create_table(self.generic_table_definition()) class CreateTableTests(AsyncTestCase):