mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Try once if AutoReconnect is raised
This commit is contained in:
parent
5aecd8aab2
commit
5604e32d57
@ -72,12 +72,17 @@ class MongoDBConnection(Connection):
|
|||||||
return self.query()[self.dbname][name]
|
return self.query()[self.dbname][name]
|
||||||
|
|
||||||
def run(self, query):
|
def run(self, query):
|
||||||
|
try:
|
||||||
try:
|
try:
|
||||||
return query.run(self.conn)
|
return query.run(self.conn)
|
||||||
except pymongo.errors.DuplicateKeyError as exc:
|
except pymongo.errors.AutoReconnect as exc:
|
||||||
raise DuplicateKeyError from exc
|
logger.warning('Lost connection to the database, '
|
||||||
|
'retrying query.')
|
||||||
|
return query.run(self.conn)
|
||||||
except pymongo.errors.AutoReconnect as exc:
|
except pymongo.errors.AutoReconnect as exc:
|
||||||
raise ConnectionError from exc
|
raise ConnectionError from exc
|
||||||
|
except pymongo.errors.DuplicateKeyError as exc:
|
||||||
|
raise DuplicateKeyError from exc
|
||||||
except pymongo.errors.OperationFailure as exc:
|
except pymongo.errors.OperationFailure as exc:
|
||||||
raise OperationError from exc
|
raise OperationError from exc
|
||||||
|
|
||||||
|
@ -79,19 +79,24 @@ def test_connection_run_errors(mock_client, mock_init_repl_set):
|
|||||||
ConnectionError)
|
ConnectionError)
|
||||||
|
|
||||||
conn = connect()
|
conn = connect()
|
||||||
query = mock.Mock()
|
|
||||||
|
|
||||||
|
query = mock.Mock()
|
||||||
query.run.side_effect = pymongo.errors.AutoReconnect('foo')
|
query.run.side_effect = pymongo.errors.AutoReconnect('foo')
|
||||||
with pytest.raises(ConnectionError):
|
with pytest.raises(ConnectionError):
|
||||||
conn.run(query)
|
conn.run(query)
|
||||||
|
assert query.run.call_count == 2
|
||||||
|
|
||||||
|
query = mock.Mock()
|
||||||
query.run.side_effect = pymongo.errors.DuplicateKeyError('foo')
|
query.run.side_effect = pymongo.errors.DuplicateKeyError('foo')
|
||||||
with pytest.raises(DuplicateKeyError):
|
with pytest.raises(DuplicateKeyError):
|
||||||
conn.run(query)
|
conn.run(query)
|
||||||
|
assert query.run.call_count == 1
|
||||||
|
|
||||||
|
query = mock.Mock()
|
||||||
query.run.side_effect = pymongo.errors.OperationFailure('foo')
|
query.run.side_effect = pymongo.errors.OperationFailure('foo')
|
||||||
with pytest.raises(OperationError):
|
with pytest.raises(OperationError):
|
||||||
conn.run(query)
|
conn.run(query)
|
||||||
|
assert query.run.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_check_replica_set_not_enabled(mongodb_connection):
|
def test_check_replica_set_not_enabled(mongodb_connection):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user