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')
|
||||
try:
|
||||
yield True
|
||||
except (Exception, Timeout):
|
||||
pass
|
||||
try:
|
||||
conn.execute('ROLLBACK')
|
||||
conn.isolation_level = orig_isolation_level
|
||||
self.conn = conn
|
||||
except (Exception, Timeout):
|
||||
logging.exception(
|
||||
_('Broker error trying to rollback locked connection'))
|
||||
conn.close()
|
||||
finally:
|
||||
try:
|
||||
conn.execute('ROLLBACK')
|
||||
conn.isolation_level = orig_isolation_level
|
||||
self.conn = conn
|
||||
except (Exception, Timeout):
|
||||
logging.exception(
|
||||
_('Broker error trying to rollback locked connection'))
|
||||
conn.close()
|
||||
|
||||
def _new_db_id(self):
|
||||
device_name = os.path.basename(self.get_device_path())
|
||||
|
@ -914,13 +914,27 @@ class TestDatabaseBroker(unittest.TestCase):
|
||||
pass
|
||||
with broker.lock():
|
||||
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'),
|
||||
timeout=.1)
|
||||
broker2._initialize = stub
|
||||
with broker.lock():
|
||||
with self.assertRaises(LockTimeout) as raised, \
|
||||
broker2.lock():
|
||||
pass
|
||||
# broker2 raises the timeout
|
||||
with self.assertRaises(LockTimeout) as raised:
|
||||
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),
|
||||
'0.1 seconds: %s' % broker.db_file)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user