DB locks shouldn't squelch errors
Change-Id: Icca4718a1cea1d21c1e858e9048552946a9f739a
This commit is contained in:
parent
a1939cba03
commit
861d13c513
@ -581,16 +581,15 @@ class DatabaseBroker(object):
|
|||||||
conn.execute('BEGIN IMMEDIATE')
|
conn.execute('BEGIN IMMEDIATE')
|
||||||
try:
|
try:
|
||||||
yield True
|
yield True
|
||||||
except (Exception, Timeout):
|
finally:
|
||||||
pass
|
try:
|
||||||
try:
|
conn.execute('ROLLBACK')
|
||||||
conn.execute('ROLLBACK')
|
conn.isolation_level = orig_isolation_level
|
||||||
conn.isolation_level = orig_isolation_level
|
self.conn = conn
|
||||||
self.conn = conn
|
except (Exception, Timeout):
|
||||||
except (Exception, Timeout):
|
logging.exception(
|
||||||
logging.exception(
|
_('Broker error trying to rollback locked connection'))
|
||||||
_('Broker error trying to rollback locked connection'))
|
conn.close()
|
||||||
conn.close()
|
|
||||||
|
|
||||||
def _new_db_id(self):
|
def _new_db_id(self):
|
||||||
device_name = os.path.basename(self.get_device_path())
|
device_name = os.path.basename(self.get_device_path())
|
||||||
|
@ -914,13 +914,27 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
with broker.lock():
|
with broker.lock():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
with self.assertRaises(RuntimeError) as raised, broker.lock():
|
||||||
|
raise RuntimeError('boom!')
|
||||||
|
self.assertEqual(raised.exception.args[0], 'boom!')
|
||||||
|
|
||||||
broker2 = DatabaseBroker(os.path.join(self.testdir, '1.db'),
|
broker2 = DatabaseBroker(os.path.join(self.testdir, '1.db'),
|
||||||
timeout=.1)
|
timeout=.1)
|
||||||
broker2._initialize = stub
|
broker2._initialize = stub
|
||||||
with broker.lock():
|
with broker.lock():
|
||||||
with self.assertRaises(LockTimeout) as raised, \
|
# broker2 raises the timeout
|
||||||
broker2.lock():
|
with self.assertRaises(LockTimeout) as raised:
|
||||||
pass
|
with broker2.lock():
|
||||||
|
pass
|
||||||
|
self.assertEqual(str(raised.exception),
|
||||||
|
'0.1 seconds: %s' % broker.db_file)
|
||||||
|
|
||||||
|
# and the timeout bubbles up out of broker.lock()
|
||||||
|
with self.assertRaises(LockTimeout) as raised:
|
||||||
|
with broker.lock():
|
||||||
|
with broker2.lock():
|
||||||
|
pass
|
||||||
self.assertEqual(str(raised.exception),
|
self.assertEqual(str(raised.exception),
|
||||||
'0.1 seconds: %s' % broker.db_file)
|
'0.1 seconds: %s' % broker.db_file)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user