Mock out all RPC calls with a fixture
Mock out the rpc proxy calls used by various agents to prevent unit tests from blocking for 10+ seconds while waiting for a timeout. This happened with the OVS agent unit tests recently in Change-ID Idd770a85a9eabff112d9613e75d8bb524020234a. This change results in a reduction from 330.8 seconds to 2.7 seconds for the neutron.tests.unit.openvswitch.test_ovs_neutron_agent test module. Closes-Bug: #1372076 Change-Id: I5e6794dc33c64c8fe309d8e72a8af3385c7d4442
This commit is contained in:
parent
bed3769e25
commit
37646d26b9
@ -125,11 +125,25 @@ class BaseTestCase(testtools.TestCase):
|
|||||||
'neutron.common.exceptions.NeutronException.use_fatal_exceptions',
|
'neutron.common.exceptions.NeutronException.use_fatal_exceptions',
|
||||||
fake_use_fatal_exceptions))
|
fake_use_fatal_exceptions))
|
||||||
|
|
||||||
|
self.setup_rpc_mocks()
|
||||||
|
|
||||||
|
if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml':
|
||||||
|
raise self.skipException('XML Testing Skipped in Py26')
|
||||||
|
|
||||||
|
self.setup_config()
|
||||||
|
self.addOnException(self.check_for_systemexit)
|
||||||
|
|
||||||
|
def setup_rpc_mocks(self):
|
||||||
# don't actually start RPC listeners when testing
|
# don't actually start RPC listeners when testing
|
||||||
self.useFixture(fixtures.MonkeyPatch(
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
'neutron.common.rpc.Connection.consume_in_threads',
|
'neutron.common.rpc.Connection.consume_in_threads',
|
||||||
fake_consume_in_threads))
|
fake_consume_in_threads))
|
||||||
|
|
||||||
|
# immediately return RPC calls
|
||||||
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
|
'neutron.common.rpc.RpcProxy._RpcProxy__call_rpc_method',
|
||||||
|
mock.MagicMock()))
|
||||||
|
|
||||||
self.useFixture(fixtures.MonkeyPatch(
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
'oslo.messaging.Notifier', fake_notifier.FakeNotifier))
|
'oslo.messaging.Notifier', fake_notifier.FakeNotifier))
|
||||||
|
|
||||||
@ -144,12 +158,6 @@ class BaseTestCase(testtools.TestCase):
|
|||||||
self.addCleanup(n_rpc.cleanup)
|
self.addCleanup(n_rpc.cleanup)
|
||||||
n_rpc.init(CONF)
|
n_rpc.init(CONF)
|
||||||
|
|
||||||
if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml':
|
|
||||||
raise self.skipException('XML Testing Skipped in Py26')
|
|
||||||
|
|
||||||
self.setup_config()
|
|
||||||
self.addOnException(self.check_for_systemexit)
|
|
||||||
|
|
||||||
def check_for_systemexit(self, exc_info):
|
def check_for_systemexit(self, exc_info):
|
||||||
if isinstance(exc_info[1], SystemExit):
|
if isinstance(exc_info[1], SystemExit):
|
||||||
self.fail("A SystemExit was raised during the test. %s"
|
self.fail("A SystemExit was raised during the test. %s"
|
||||||
|
@ -136,6 +136,9 @@ class TestOvsNeutronAgent(base.BaseTestCase):
|
|||||||
'FixedIntervalLoopingCall',
|
'FixedIntervalLoopingCall',
|
||||||
new=MockFixedIntervalLoopingCall)):
|
new=MockFixedIntervalLoopingCall)):
|
||||||
self.agent = ovs_neutron_agent.OVSNeutronAgent(**kwargs)
|
self.agent = ovs_neutron_agent.OVSNeutronAgent(**kwargs)
|
||||||
|
# set back to true because initial report state will succeed due
|
||||||
|
# to mocked out RPC calls
|
||||||
|
self.agent.use_call = True
|
||||||
self.agent.tun_br = mock.Mock()
|
self.agent.tun_br = mock.Mock()
|
||||||
self.agent.sg_agent = mock.Mock()
|
self.agent.sg_agent = mock.Mock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user