Merge "Fix some slow unit tests"

This commit is contained in:
Jenkins 2016-12-10 02:36:33 +00:00 committed by Gerrit Code Review
commit cb459dec48
4 changed files with 14 additions and 3 deletions

View File

@ -813,10 +813,12 @@ class OVS_Lib_Test(base.BaseTestCase):
self.assertEqual(1, self.br._get_port_ofport('1'))
def test_get_port_ofport_retry_fails(self):
# after 16 calls the retry will timeout and raise
# reduce timeout for faster execution
self.br.vsctl_timeout = 1
# after 7 calls the retry will timeout and raise
with mock.patch.object(
self.br, 'db_get_val',
side_effect=[[] for _ in range(16)]):
side_effect=[[] for _ in range(7)]):
self.assertRaises(tenacity.RetryError,
self.br._get_port_ofport, '1')

View File

@ -91,6 +91,9 @@ class TestDeadLockDecorator(base.BaseTestCase):
self.assertIsNone(self._decorated_function(1, e))
def test_multi_exception_raised_on_exceed(self):
# limit retries so this doesn't take 40 seconds
mock.patch.object(db_api._retry_db_errors, 'max_retries',
new=2).start()
e = exceptions.MultipleExceptions([ValueError(), db_exc.DBDeadlock()])
with testtools.ExpectedException(exceptions.MultipleExceptions):
self._decorated_function(db_api.MAX_RETRIES + 1, e)

View File

@ -69,6 +69,9 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase):
self.assertEqual(expected, entry)
def test__create_dvr_mac_address_retries_exceeded_retry_logic(self):
# limit retries so test doesn't take 40 seconds
mock.patch('neutron.db.api._retry_db_errors.max_retries',
new=2).start()
self._create_dvr_mac_entry('foo_host_1', 'non_unique_mac')
with mock.patch.object(dvr_mac_db.utils, 'get_random_mac') as f:
f.return_value = 'non_unique_mac'

View File

@ -377,6 +377,8 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2,
def test_create_network_segment_allocation_fails(self):
plugin = directory.get_plugin()
mock.patch.object(db_api._retry_db_errors, 'max_retries',
new=2).start()
with mock.patch.object(
plugin.type_manager, 'create_network_segments',
side_effect=db_exc.RetryRequest(ValueError())
@ -386,7 +388,8 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2,
req = self.new_create_request('networks', data)
res = req.get_response(self.api)
self.assertEqual(500, res.status_int)
self.assertEqual(db_api.MAX_RETRIES + 1, f.call_count)
# 1 + retry count
self.assertEqual(3, f.call_count)
class TestExternalNetwork(Ml2PluginV2TestCase):